WebService fails, what do I wrong?

Hey everybody,

I just try to get some information from a JSON file. If I have an JSON file locally on my Computer it works (works means I get the content of the JSON file). But as soon as I upload it, it does not work. For this example I want to get the content of the JSON file hosted here: http://blockchain.info/ticker (On webOS that works with Enyo 1. I know there were a lot of changes since that, but why does the WebService work with files that are locally on my machine but fails if the file is online?) Here now my sample code:

// In the Components array:
{
name: "webService",
kind: "WebService",
url: "http://blockchain.info/ticker",
onResponse: "webServiceResponse",
onError: "webServiceError",
},
// ...

rendered: function() {
this.inherited(arguments);
this.$.webService.send({ jsonp: true });
},

webServiceResponse: function(inSender, inEvent) {
enyo.log("webServiceResponse: "+inEvent.data);
enyo.log(inEvent.ajax);
},

webServiceError: function(inSender, inEvent) {
enyo.log("webServiceError: "+inEvent.data);
enyo.log(inEvent.ajax);
},
Console output: [17:18:54.696] webServiceError: 0

Any ideas?
What means the error code 0 (zero)?



Comments

  • I think the error handler gets the response status code as its first argument, so that's why it's 0.

    The underlying issue might be due to cross-domain origin restrictions. You can verify this by putting your app source up on the same domain and accessing it online.

    If you're developing with Chrome, make sure you have at least the --disable-web-security flag set to eliminate the cross-domain check.
  • edited May 2013
    Yes, seems like this is a cross-domain issue like you described it above. I never heard about such a cross-domain check yet. So I need to find out how to disable that, because 1st my app is a packaged firefoxOS app and 2nd the JSON file is online, not within the package of the app...

    Thanks

    P.S. If that's possible. Otherwise I need to find another way
  • Ah I found something interesting... http://bugs.jquery.com/ticket/13394
  • For me it works now. Here is the solution:

    1st: Add systemXHR to the manifest.webapp (FirefoxOS):

    "permissions": {
    "systemXHR": {}
    }
    2nd, you need to edit the function "getXMLHttpRequest" of the xhr.js file (enyo.xhr kind).

    getXMLHttpRequest: function(inParams) {
    try {
    // only use XDomainRequest when it exists, no extra headers were set, and the
    // target URL maps to a domain other than the document origin.
    if (enyo.platform.ie < 10 && window.XDomainRequest && !inParams.headers &&
    !this.inOrigin(inParams.url) && !/^file:\/\//.test(window.location.href)) {
    return new XDomainRequest();
    }
    } catch(e) {}
    try {
    return new XMLHttpRequest({ "mozSystem": true }); // EDIT THIS LINE
    } catch(e) {}
    return null;
    }
    You need to add { "mozSystem": true }. The enyo team should edit the method and write another if that checks if you're working with ffOS. If so, return new XMLHttpRequest({ "mozSystem": true }); else, return the "standard" (empty constructor). I'm not a professional here but I guess that would be the best solution?
  • edited May 2013
    I've made https://enyojs.atlassian.net/browse/ENYO-2457 to track the work on this. From the FxOS docs, you also need the anonymous flag for this, so I combined this request with other work to support that.
  • You don't need an anonymous flag for mozSystem to work. I've sent a pull request implementing this but I can't seem to be able to comment on the JIRA tracker.
  • @andregarzia‌ yeah, JIRA permissions got messed up in a system migration earlier this year. We'll try to get that fixed, and I'm reviewing your PRs ASAP.
  • @unwiredben‌ thanks for the feedback! Those are just some simple PR so that I understand how to contribute back. If there is anything wrong, just comment there or here and I will fix it.
  • @unwiredben‌ fixed the documentation there. :-)
  • and merged in today!
  • unwiredben, thanks for adding mozSystem support to enyo's xhr.js.
    For users of the high-level API enyo.Ajax, there is still no way to set this option, though, as far as I can see:
    The option mozSysteme needs to be set as a top-level entry in the options hash like this:
    enyo.xhr.request({mozSystem: true})
    However enyo.Ajax.request doesn't allow to add new top-level entries to the parameters when calling enyo.xhr.request - see https://github.com/enyojs/enyo/blob/2.4.0/source/ajax/Ajax.js#L133
Sign In or Register to comment.