Web 应用程序中的跨源请求

在我的 Tizen 系统应用程序中,我发出了一个跨源 AJAX 请求,它在 Tizen 的浏览器中运行良好,但是当我将其打包为 Web 应用程序时,跨源请求无法运行.我已经在模拟器和真实设备上对其进行了测试.我也使用 webkit 检查器记录网络日志,截图如下:

In my application for Tizen system, I make a cross origin AJAX request, it works well in Tizen's browser, but when I package it as web application, the cross origin request can't work. I've tested it both on emulator and real device. I also use the webkit inspector record the network log, the screenshot is as following:

有专家能告诉我为什么吗?

Could any expert tell me why?

以下是我的代码:

var url = "";//this is assigned a domain which supports cross domain access according to HTML5 specification.
var client = new XMLHttpRequest();
client.open("GET", url, true);
client.setRequestHeader("Accept-Language", 'en-us');
client.onreadystatechange = function() { alert("succeed"); }
client.send();

推荐答案

任何在外部访问的资源都应该声明(见访问外部网络资源):

Any resource that it is accessed outside should be declared(see Accessing External Network Resources):

默认情况下您无法访问外部网络资源(WARP:W3C访问请求策略).因此,您必须请求权限小部件来检索网络资源.您可以通过以下方式输入多个 URL使用访问"选项卡上的添加"按钮.对于每个 URL,您可以指定如果您想允许小部件访问 URL 子域.这允许子域栏内容可以通过鼠标点击切换.

You cannot access external network resources by default (WARP: W3C Access Requests Policy). So, you must request permissions for the widget to retrieve network resources. You can enter several URLs by using the Add button on the Access tab. For each URL, you can indicate if you want to allow the widget to access the URL sub-domains. The Allow subdomain column contents can be toggled by mouse clicks.

所以如果没有访问我们在 config.xml 中定义的案例所需的特定资源,它就无法工作:

so it cannot work without having access to the specific resource needed in our case defined in config.xml:

<access origin="http://url_resource" subdomains="true"/>

<access origin="*" subdomains="true"/>

让一切都过去.

相关文章