This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 124
zzz_archive [Cross Origin XHR]
Elliot Smith edited this page Jun 17, 2014
·
1 revision
The content of this page has been promoted to the main website at https://crosswalk-project.org/#documentation/manifest/xwalk_hosts.
Getting data from remote servers with XMLHttpRequest object is limited by the same origin policy. To allow Cross-Origin XHR, "xwalk_hosts" should be declared in manifest.json for web applications running on Crosswalk for Android.
By adding hosts or host match patterns to the "xwalk_hosts" list in manifest.json, you applications can request access to remote servers outside of its origin.
{
...
"xwalk_hosts": [
"http://crosswalk-project.org/*"
],
...
}
"xwalk_hosts" valus can be fully qualified host names, like:
Or they can be match patterns, like:
- "http://*.org/"
- "https://*/"
After adding permissions to manifest.json, you can access the target URL directly with XMLHttpRequest Object.
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://crosswalk-project.org/", true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
// Do something with xhr.responseText.
}
}
xhr.send();