cross origin request in web application

2019-02-20 09:56发布

问题:

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?

The following is my code:

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();

回答1:

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

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.

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"/>

or

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

to let everything pass.