JQuery JSONP cross domain call does nothing

Whenever I make a JSONP call through jquery to any page that I have configured (locally or on my server), all I get is a silent call. Firebug reports 200 OK, and the response looks fine. I set the warning windows to a popup with success or not appearing. It doesn't seem to matter which url I use, nothing pops up.

BUT, if I use the twitter json page, then a success warning window appears, so obviously something is wrong with my answer, but I don't know what.

As an experiment, I copied the twitter json response and uploaded it to my booroo.com domain. It should be identical, but still nothing. I set the headers on the answer page to "application / json" and utf-8, but still nothing.

Please help, I spent all day on this now, and I do not know what else to try.

$.ajax({ dataType: 'jsonp', // url: 'http://booroo.com/json.asp?callback=?', url: 'http://twitter.com/users/usejquery.json?callback=?', success: function () { alert("Success"); }, error: function(x,y,z) { alert("error"+x.responseText); } }); 

The json.asp response file contains the following classic ASP headers, and then the json response copied from twitter (I also tried others without success).

 <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% Response.Expires = 0 Response.Expiresabsolute = Now() - 1 Response.AddHeader "pragma","no-cache" Response.AddHeader "cache-control","private" Response.CacheControl = "no-cache" response.ContentType="application/json" Response.CodePage = 65001 Response.CharSet = "UTF-8" %>({"test_param":12345}); 
+4
source share
2 answers

OK, after a good night's sleep, I solved the problem. I did not understand that this is the difference between the two response formats. When I requested twitter only using my browser, the answer did not include the name of the function that confused me.

 //JSON {"name":"stackoverflow","id":5} //JSONP func({"name":"stackoverflow","id":5}); 
+1
source

You have problems because it is not what the answer looks like :)

When do you specify jsonp or callback=? , it is replaced, it actually does ?callback=functioName , which makes your answer something like this:

 {"test_param":12345} 

For this:

 functionName({"test_param":12345}); 

This is necessary for JSONP to work. Check the updated URL to see what I mean: http://twitter.com/users/usejquery.json?callback=functionName

+10
source

All Articles