mirror of
https://github.com/jquery/jquery.git
synced 2026-02-10 11:45:14 -05:00
@@ -1,3 +1,10 @@
|
||||
define([
|
||||
"../core",
|
||||
"./var/nonce",
|
||||
"./var/rquery",
|
||||
"../ajax"
|
||||
], function( jQuery, nonce, rquery ) {
|
||||
|
||||
var oldCallbacks = [],
|
||||
rjsonp = /(=)\?(?=&|$)|\?\?/;
|
||||
|
||||
@@ -5,7 +12,7 @@ var oldCallbacks = [],
|
||||
jQuery.ajaxSetup({
|
||||
jsonp: "callback",
|
||||
jsonpCallback: function() {
|
||||
var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( ajax_nonce++ ) );
|
||||
var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
|
||||
this[ callback ] = true;
|
||||
return callback;
|
||||
}
|
||||
@@ -32,7 +39,7 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
|
||||
if ( jsonProp ) {
|
||||
s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
|
||||
} else if ( s.jsonp !== false ) {
|
||||
s.url += ( ajax_rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
|
||||
s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
|
||||
}
|
||||
|
||||
// Use data converter to retrieve json after script execution
|
||||
@@ -78,3 +85,5 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
|
||||
return "script";
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
71
src/ajax/load.js
Normal file
71
src/ajax/load.js
Normal file
@@ -0,0 +1,71 @@
|
||||
define([
|
||||
"../core",
|
||||
"../ajax",
|
||||
"../traversing",
|
||||
"../selector"
|
||||
], function( jQuery ) {
|
||||
|
||||
// Keep a copy of the old load method
|
||||
var _load = jQuery.fn.load;
|
||||
|
||||
/**
|
||||
* Load a url into a page
|
||||
*/
|
||||
jQuery.fn.load = function( url, params, callback ) {
|
||||
if ( typeof url !== "string" && _load ) {
|
||||
return _load.apply( this, arguments );
|
||||
}
|
||||
|
||||
var selector, type, response,
|
||||
self = this,
|
||||
off = url.indexOf(" ");
|
||||
|
||||
if ( off >= 0 ) {
|
||||
selector = url.slice( off );
|
||||
url = url.slice( 0, off );
|
||||
}
|
||||
|
||||
// If it's a function
|
||||
if ( jQuery.isFunction( params ) ) {
|
||||
|
||||
// We assume that it's the callback
|
||||
callback = params;
|
||||
params = undefined;
|
||||
|
||||
// Otherwise, build a param string
|
||||
} else if ( params && typeof params === "object" ) {
|
||||
type = "POST";
|
||||
}
|
||||
|
||||
// If we have elements to modify, make the request
|
||||
if ( self.length > 0 ) {
|
||||
jQuery.ajax({
|
||||
url: url,
|
||||
|
||||
// if "type" variable is undefined, then "GET" method will be used
|
||||
type: type,
|
||||
dataType: "html",
|
||||
data: params
|
||||
}).done(function( responseText ) {
|
||||
|
||||
// Save response for use in complete callback
|
||||
response = arguments;
|
||||
|
||||
self.html( selector ?
|
||||
|
||||
// If a selector was specified, locate the right elements in a dummy div
|
||||
// Exclude scripts to avoid IE 'Permission Denied' errors
|
||||
jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
|
||||
|
||||
// Otherwise use the full result
|
||||
responseText );
|
||||
|
||||
}).complete( callback && function( jqXHR, status ) {
|
||||
self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
});
|
||||
@@ -1,3 +1,8 @@
|
||||
define([
|
||||
"../core",
|
||||
"../ajax"
|
||||
], function( jQuery ) {
|
||||
|
||||
// Install script dataType
|
||||
jQuery.ajaxSetup({
|
||||
accepts: {
|
||||
@@ -55,3 +60,5 @@ jQuery.ajaxTransport( "script", function( s ) {
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
5
src/ajax/var/nonce.js
Normal file
5
src/ajax/var/nonce.js
Normal file
@@ -0,0 +1,5 @@
|
||||
define([
|
||||
"../../core"
|
||||
], function( jQuery ) {
|
||||
return jQuery.now();
|
||||
});
|
||||
3
src/ajax/var/rquery.js
Normal file
3
src/ajax/var/rquery.js
Normal file
@@ -0,0 +1,3 @@
|
||||
define(function() {
|
||||
return /\?/;
|
||||
});
|
||||
@@ -1,3 +1,8 @@
|
||||
define([
|
||||
"../core",
|
||||
"../ajax"
|
||||
], function( jQuery ) {
|
||||
|
||||
jQuery.ajaxSettings.xhr = function() {
|
||||
try {
|
||||
return new XMLHttpRequest();
|
||||
@@ -109,3 +114,5 @@ jQuery.ajaxTransport(function( options ) {
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user