Firefox OS packaged apps and XMLHttpRequests

冷暖自知 提交于 2019-11-30 15:59:40

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

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"
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!