Firefox OS packaged apps and XMLHttpRequests

前端 未结 4 1595
日久生厌
日久生厌 2021-01-03 09:25

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

相关标签:
4条回答
  • 2021-01-03 09:44

    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/

    0 讨论(0)
  • 2021-01-03 09:47

    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.

    0 讨论(0)
  • 2021-01-03 09:52

    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"
        }
    }
    
    0 讨论(0)
  • 2021-01-03 09:59

    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});
    
    0 讨论(0)
提交回复
热议问题