Jsonp request

Hey guys,

I'm pretty new to enyo and currently I try to get a json from a web service. Because I'm requesting a different domain I'm using jsonpRequest, but the content doesn't get wrapped by the callback name. I used enyo.log so i figured out that my handling method doesn't even get called when I receive the json.

So can I handle the json in a different way??

That's my code:
    name: "UList",
    components: [
        {kind: "Button", ontap: "tapped", content: "Load data"},
        {name: "List", tag: "ul", allowHtml: true},
    rendered: function(){
        var request = new enyo.JsonpRequest({
            url: "https://api.fanreport.com/at/rest/state",
            callbackName: "callback"

        request.response(enyo.bind(this, "processSearchResults"));
    tapped: function(){

    processSearchResults: function(inRequest, inResponse){
        var output = "";
        for(i = 0; i < inResponse.length; i++){
            output = inResponse[i].name;
            this.$.List.createComponent({content: output, tag: "li"});
Thank you.


  • edited February 2013
    Channeling Ben: "paste code first, then highlight, then choose the 'code' button to have it format properly with <pre> and <code> tags.

    You are probably getting an error from the service so .response() isn't triggering. Add something like:
    request.error(enyo.bind(this, function() {
       this.log("OH NO!");
    And see if you have anything you can use in there to see what's going on.
  • I added your code, but nothing happened.
    I guess it's not a service problem, because with the development tool of chrome I can see that I receive the json and I see all the data, but they're not getting displayed.
  • Very strange that neither response nor error are being called. Is this a "long-running" service that never sends readyState 4?
  • @SebastianSchenk: Sorry if this is a stupid question you've already considered but are you 110% sure the server site API supports JSONP? It is something only they can allow - you cannot make any changes to your enyo code to make their response JSONP compatible. (As I understand it).
  • @psarin: no, unfortunately I'm not sure whether they support jsonp, but since I've received a json and not an error message or something like this I thought it will work anyway. I've noticed that the received json isn't wrapped by the callbackName, which is the case if I perform a twitter jsonpRequest for example (twitter: enyo_jsonp_callback_1({"completed_in":0.064,..... / my service: [{"state_id":"4","region_id":"1...)

    Does that mean there is no jsonp support???

    Is there another way to get the json???
  • You may want to email them and ask them if they support it and/or can enable it on their end.

    A few things: 1) if you are developing to package your app for phones and such (e.g., via PhoneGap), cross domain scripting is allowed by mobile apps; 2) I believe you can enable cross domain for Chrome via a command line switch (of course, that only helps you in developing/debugging apps for #1; 3) if you have a back end server, you can proxy the results from the server to your app via server side application.
Sign In or Register to comment.