Jsonp Request - Response Function never called.

edited May 2013 in Enyo 2
I'm trying to make a Jsonp request to an API. In Chrome dev tools, I can see that the request is being sent and the response data is as expected, but my response function is never called. Code below:

search: function() {

var request = new enyo.JsonpRequest({
url: "http://api.sportsdatallc.org/nfl-t1/2012/REG/1/DAL/NYG/plays/28140456-0132-4829-ae38-d68e10a5acc9.json",
// url: "http://search.twitter.com/search.json"
});

request.response(enyo.bind(this, "processSearchResults"));
request.go({
// q: 'tornado'
api_key: 'REMOVED_FOR_THIS_POST'
});
},

processSearchResults: function(inRequest, inResponse) {
console.log("processing!");
}
What's weird is that if I uncomment this example to use the Twitter URL and search params, then the processSearchResults() function gets called. The only difference I can spot is that the response header Content-Type for the Twitter request is application/javascript whereas the sportsdatallc response Content-Type is application/json.

Any ideas?

Comments

  • You have to request from a server that supports JSONP responses. A raw JSON file won't work -- you need a server on the other end that will take the function parameter sent to it and use that to return valid JavaScript code using that function name to return the data.
  • Ah, now it makes sense. Thanks for humoring me and my very tenuous grasp of the JSONP concept overall.
Sign In or Register to comment.