The $. getjson method of jquery supports cross-origin.
Page request:
$. Getjson (URL + '? Callback =? ', {Operate: 'add'}, function (RES ){}});
It is actually another encapsulation of $. Ajax.
$. Ajax ({type: 'get', URL: URL, data :{}, datatype: 'jsonp', callback: 'json _ callback', success: function (RES) {}})
Server PHP:
$ Callback = $ _ Get ['callback']; print_r ("$ callback ({key: \" value \"});");
Principle:
You need to upload a callback function name to the server. The server obtains the callback function name and returns the returned data to the client in the form of parameters, so that the client can be tuned.
Callback =? That is, if the callback function name is not specified, jquery will automatically generate one, for example, jsonp12148037045654, which can be viewed using firebug.
When the server receives this callback, the return format is jsonp12148037045654 ({operate: 'add'}). It is not like the definition of a function.
Using $. Ajax to specify the callback parameter is equivalent to customizing this callback as "json_callback", which does not need to be automatically generated by jquery.
Ajax cross-origin requests do not support post. Remember.
Official jquery Website:
Http://api.jquery.com/jQuery.getJSON/#urldatacallback