3 var jsc = jQuery.now(),
4 jsre = /(\=)(?:\?|%3F)(&|$)|()(?:\?\?|%3F%3F)()/i,
7 // Default jsonp settings
10 jsonpCallback: function() {
11 return "jsonp" + jsc++;
14 // Detect, normalize options and install callbacks for jsonp requests
15 }).ajaxPrefilter("json jsonp", function(s, originalSettings) {
17 if ( s.dataTypes[ 0 ] === "jsonp" ||
18 originalSettings.jsonp ||
19 originalSettings.jsonpCallback ||
21 typeof(s.data) === "string" && jsre.test(s.data) ) {
23 var responseContainer,
24 jsonpCallback = s.jsonpCallback =
25 jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback,
26 previous = window[ jsonpCallback ],
27 url = s.url.replace(jsre, "$1" + jsonpCallback + "$2"),
28 data = s.url === url && typeof(s.data) === "string" ? s.data.replace(jsre, "$1" + jsonpCallback + "$2") : s.data;
30 if ( url === s.url && data === s.data ) {
31 url += (rquery_jsonp.test( url ) ? "&" : "?") + s.jsonp + "=" + jsonpCallback;
37 window [ jsonpCallback ] = function( response ) {
38 responseContainer = [response];
41 s.complete = [function() {
43 // Set callback back to previous value
44 window[ jsonpCallback ] = previous;
46 // Call if it was a function and we have a response
48 if ( responseContainer && jQuery.isFunction ( previous ) ) {
49 window[ jsonpCallback ] ( responseContainer[0] );
52 // else, more memory leak avoidance
53 try{ delete window[ jsonpCallback ]; } catch(e){}
58 // Use data converter to retrieve json after script execution
59 s.converters["script json"] = function() {
60 if ( ! responseContainer ) {
61 jQuery.error( jsonpCallback + " was not called" );
63 return responseContainer[ 0 ];
66 // force json dataType
67 s.dataTypes[ 0 ] = "json";