Why jQuery ajax (JSONP) works without `& callback =`, but does not work with `& callback = functionname`

I need to make a JSONP call.

Ajax function call:

$.ajax({ url: myPath, dataType: 'jsonp', success: function(data) { alert("hello"); } }); 

call to getJSON function:

 $.getJSON(myPath + '&callback=prova?', function(data) { alert("hello"); }); 

with getJSON (using & callback = prova to set the JSONP protocol) I get a 200 error. .ajax () also works. What for? I want to use getJSON here ...

+4
source share
2 answers

Should you use callback=? , but not callback=prova? if you want your request to be processed as JSONP:

 $.getJSON(myPath + '&callback=?', function(data) { alert("hello"); });​ 
+3
source

try it

 $.getJSON(myPath + '?callback=prova', function(data) { alert("hello"); }); 
-1
source

Source: https://habr.com/ru/post/1401785/


All Articles