I\'ve been looking into packaged apps for Firefox OS and I\'m relying on the Simulator since I don\'t have a build of the OS on a device. I\'m having trouble with XHR reque
Take a look on Rob Nyman Boilerplate, he have a working XHR demo
https://github.com/robnyman/Firefox-OS-Boilerplate-App
http://robnyman.github.com/Firefox-OS-Boilerplate-App/
For Backbone or other Javascript framework using JQuery $.ajax under the hood use:
$.ajaxSetup( {
xhr: function() {return new window.XMLHttpRequest({mozSystem: true});}
});
I don't think that you need to use CORS. My app is working fine in simulator without CORS but fails to call remote REST server if launched on local server.
Be aware that if you forgot to set
dataType: "text"
for some $.ajax calls (for example load html template) you can get XMLDocument as a result while desktop browsers returns string.
To enable CORS in my Firefox OS app, I had to enable systemXHR permission in the apps manifest.webapp file:
"permissions": {
"systemXHR" : {
"description" : "Required to access remote api"
}
}
Note that to use the systemXHR permission you also need to pass a special argument when creating the request object, e.g.
var xhr = new XMLHttpRequest({mozSystem: true});