Wednesday 15 February 2012

jQuery AJAX jsonp can't work with the response -


So, I wrote a WordPress plugin to create a JSON file with the latest x articles, after which it has a URL, which is called CloudFront Is being cached from.

In this way, I am using my file (in the browser):

And I get my JSON format response file:

 < Code> {"id": 55142, "title": "A new model model productivity para espa \ u00f1a", "url": ....   

Now, this is an async I use the JS code to use the file in mode:

  var jqXHR = $ .ajax ({type: 'GET', url: 'http://mm.site. Com / wp-content / uploads / plug / plug.json ', contentType: "application / json", datatype:' jsonp '}); JqXHR.done (function (json) {console.log (json);}) .error (function (e) {console.log (e);}) .ways (function (test) {console.log (test); }); Now, the Curiosity portion is that under the Networks tab (firebug, or Chrome Dev Dev), I see the request and it is a  200 status code  and The contents of the file, however, I do not see the response in  .done () , so I can not use it and can not work with it.  

Why can any one think?

Update

instead of json , jsonp will not control this due to cross-root . Remember that I keep the file on the server from Amazon's CloudFront. I tried fixing, but there is no luck, so if you do not have any other option, then I'll be able to send it to jsonp

EDIT: Felix registers the code as a callback, in the form of a cling notes, the main callback is a jQuery handler that looks like: jQuery> Callback = jQuery19104353667694941068_1372008424415 & amp; Foo = bar

A fixed file will not be able to respond properly to this call because it generates jQuery Headler's Name Dynamically

Setting jsonpCallback: "Definitive Name" if the fixed file is in the form fixedName ({.. some variable ..}), then .


Original Response:

jsonp does not fire done method. This adds a script tag like this:

  & lt; Script type = "text / javascript" src = "http://anothersite.com/?callback=whatToDoWhenDone" & gt; & Lt; / Script & gt;   

The expected response will be the JS code which will call whatToDoWhenDone and JSON objects as arguments:

  whatToDoWhenDone ( {"Id": 55142, "title": "a new model model productivity para espa \ u00f1a", "url": ....});   

If you do not need to use jsonp , then change it to json only.

No comments:

Post a Comment