Your request is only triggered once because of how jsonp works.
Jsonp means adding a script tag to a page from an external domain to bypass cross-site scripting protection built into modern browsers (and now IE6 and 7 as of April 2011). For the script to interact with the rest of the script on the page, the loaded script must call the function on the page. This function must exist in the global namespace, and it can be only one function. In other words, without jQuery, a single jsonp request would look like this:
<script> function loadJson(json) { </script> <script src="//outsidedomain.com/something.js"></script>
Where something.js would look like this:
loadJson({name:'Joe'})
something.js in this case has a hard-coded callback to load the JSON that it carries, and the page has a hard-coded loadJson function that waits for scripts like this to load and a call.
Now suppose you want to be able to download json from several sources and tell when each one finishes or even downloads JSON from one source several times, and be able to tell when each call ends, even if one call is delayed, so it ends after later call. This hard-coded approach will no longer work for two reasons:
Each download of something.js calls the same loadback request loadJson () - you have no way to find out which request is sent with which response.
Caching - as soon as you download something.js once, the browser will not again request a server for it - it will simply return it from the cache, destroying your plan.
You can solve both of them by telling the server to wrap JSON differently each time, and the simple way is to pass this information in the querystring parameter, for example ?callback=loadJson12345 . As if your page looked like this:
<script> function loadJson1(json) { </script> <script src="//outsidedomain.com/something.js?callback=loadJson1"></script> <script src="//outsidedomain.com/somethingelse.js?callback=loadJson2"></script>
With jQuery, all this is abstracted out to make you look like a regular $ .ajax call, which means you expect the success function to be launched. To ensure that the correct success function is triggered for each jsonp load, jQuery creates a long random name for the callback function in the global namespace, for example JQuery1233432432432432, passes that value as the callback parameter in the request, then waits for the script to load. If everything works correctly, the script that loads the calls is the requested jQuery callback function, which in turn starts the success handler from the $ .ajax call.
Note that โworking correctlyโ requires the server side to read the ?callback Callback querystring parameter and include this in the response, for example ?callback=joe โ joe({... If the static file or server does not play this way, you probably , you have to consider the file as cached - see below.
Caching
If you want your json to be cached, you can force JQuery to do something closer to my first example by setting cache: true and setting the jsonpCallback property to a string hardcoded to the cached json file. For example, this static json:
loadJoe({name:'Joe'})
It can be loaded and cached in jQuery, for example:
$.ajax({ url: '//outsidedomain.com/loadjoe.js', dataType: 'jsonp', cache: true, jsonpCallback: 'loadJoe', success: function(json) { ... } });