I maintain my JSONP JavaScript file on a static file server - GitHub Pages.
This means that I cannot dynamically set the name of the JSONP callback function on the server ...
Dynamic Example - PHP
header('Content-Type: text/javascript; charset=utf8');
$data = '{ "foo":"bar" }'; // json string
echo $_GET['callback'] .'('.$data.');'; // function name set via ?callback=xyz
jQuery.ajax () has a parameter jsonpCallbackto determine the name of the static callback function. Therefore, I can server a javascript file, for example. test-jsonp.jswith the following contents:
Static Example - JavaScript File
jsonpCallbackABC({ "foo":"bar" });
However, jQuery documentation recommends static .
http://api.jquery.com/jQuery.ajax/
jsonpCallback
JSONP. jQuery. , jQuery , . , GET.
- JSONP?