3 var jsc = jQuery.now(),
7 // Default jsonp callback name
8 jQuery.ajaxSettings.jsonpCallback = function() {
9 return "jsonp" + jsc++;
12 // Normalize jsonp queries
13 // 1) put callback parameter in url or data
14 // 2) sneakily ensure transportDataType is json
15 // 3) ensure options jsonp is always provided so that jsonp requests are always
16 // json request with the jsonp option set
17 jQuery.ajax.prefilter("json jsonp", function(s) {
19 var transportDataType = s.dataTypes[ 0 ];
21 s.dataTypes[ 0 ] = "json";
24 transportDataType === "jsonp" ||
25 transportDataType === "json" && ( jsre.test(s.url) || typeof(s.data) === "string" && jsre.test(s.data) ) ) {
27 var jsonp = s.jsonp = s.jsonp || "callback",
28 jsonpCallback = s.jsonpCallback =
29 jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback,
30 url = s.url.replace(jsre, "=" + jsonpCallback + "$1"),
31 data = s.url == url && typeof(s.data) === "string" ? s.data.replace(jsre, "=" + jsonpCallback + "$1") : s.data;
33 if ( url == s.url && data == s.data ) {
34 url = url += (rquery_jsonp.test( url ) ? "&" : "?") + jsonp + "=" + jsonpCallback;
41 // Bind transport to json dataType
42 }).transport("json", function(s) {
46 // Put callback in place
47 var responseContainer,
48 jsonpCallback = s.jsonpCallback,
49 previous = window[ jsonpCallback ];
51 window [ jsonpCallback ] = function( response ) {
52 responseContainer = [response];
55 s.complete = [function() {
57 // Set callback back to previous value
58 window[ jsonpCallback ] = previous;
60 // Call if it was a function and we have a response
62 if ( responseContainer && jQuery.isFunction ( previous ) ) {
63 window[ jsonpCallback ] ( responseContainer[0] );
66 // else, more memory leak avoidance
67 try{ delete window[ jsonpCallback ]; } catch(e){}
72 // Use data converter to retrieve json after script execution
73 s.dataConverters["script json"] = function() {
74 if ( ! responseContainer ) {
75 jQuery.error( jsonpCallback + " was not called" );
77 return responseContainer[ 0 ];
80 // Delegate to script transport