本文介绍了跨域JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在域xyz.com上有一个网页,其中有一个从cdn domain cdn.xyz.com下载的javascript。浏览器是否考虑通过javascript跨域调用在xyz.com(xyz.com/service.svc)上调用服务,因为js是从cdn.xyz.com下载的?

I have a web page on domain xyz.com that has a javascript being downloaded from cdn domain cdn.xyz.com. Does the browser consider calling a service on xyz.com (xyz.com/service.svc) from the javascript a cross domain call since js is downloaded from cdn.xyz.com?

如果是,cdn.xyz.com上的javascript是否可以在xyz.com上调用服务而无需返回jsonp服务?

If yes, Can the javascript on cdn.xyz.com call a service on xyz.com without having the service to return jsonp?

考虑哪个域名浏览器从javascript进行服务调用?它是从javascript下载的域还是主要请求的域?

Which domain is considered by the browser on making a service call from javascript? Is it the domain the javascript is downloaded from or the domain of the primary request?

推荐答案

不。原始域是从中引用javascript的HTML的域。这个javascript来自哪个域并不重要。

No. The origin domain is the domain from which originated the HTML that referenced the javascript. It doesn't matter from which domain does this javascript came.

如果反之亦然,请考虑一下。谷歌CDN甚至不存在于jQuery,因为你只能将AJAX请求发送到 http://google.com 哪种方式限制了应用程序的数量。

Just think for a second if the contrary was true. Google CDN wouldn't even exist for jQuery since you would be able to send AJAX requests only to http://google.com which kinda restricts the number of applications.

在您的具体示例中, http://xyz.com 。因此,即使您的javascript文件是从 http://cdn.xyz引用的,您也可以完美地将AJAX请求发送到 http://xyz.com .com

In your specific example that would be http://xyz.com. So you can perfectly fine send AJAX requests to http://xyz.com even if your javascript file was referenced from http://cdn.xyz.com.

这篇关于跨域JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 04:47