Skip to content

Instantly share code, notes, and snippets.

@arcturus
Created December 28, 2012 20:34
Show Gist options
  • Save arcturus/4401599 to your computer and use it in GitHub Desktop.
Save arcturus/4401599 to your computer and use it in GitHub Desktop.
How to do a cross domain request in Firefox OS
/*
YOU'LL BE ABLE TO PERFORM A CROSS DOMAIN REQUEST IF YOUR APP IS CERTIFIED OR PRIVILEDGED.
FOR MORE INFO CHECK THE PERMISSIONS MATRIX: https://docs.google.com/spreadsheet/ccc?key=0Akyz_Bqjgf5pdENVekxYRjBTX0dCXzItMnRyUU1RQ0E#gid=0
First you'll need to setup the permission for doing the cross domain request on your application manifest.
Go to your app manifest, to the permissions section and add the following:
"systemXHR": {}
Now let's create the xhr object, it needs a special parameter, take a look:
*/
var xhr = new XMLHttpRequest({ mozSystem: true });
// Use the xhr object as usual ...
// When checking for the result, you'll look for response status 200 OR (AND THIS IS IMPORTANT) 0
xhr.onload = function(e) {
if (xhr.status === 200 || xhr.status === 0) {
// Do your stuff here
} else {
// An error happened
}
}
@luiseduardohd
Copy link

Did you know any way to do web services request what doesnt need modify server config ? i have an existent web service and i want to connect the firefox app to that.

@mozfreddyb
Copy link

Hosted apps should work without systemXHR and mozSystem, shouldn't they?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment