9 // Optional event/alias dependency
11 ], function( jQuery ) {
13 // Keep a copy of the old load method
14 var _load = jQuery.fn.load;
17 * Load a url into a page
19 jQuery.fn.load = function( url, params, callback ) {
20 if ( typeof url !== "string" && _load ) {
21 return _load.apply( this, arguments );
24 var selector, type, response,
26 off = url.indexOf( " " );
29 selector = jQuery.trim( url.slice( off ) );
30 url = url.slice( 0, off );
34 if ( jQuery.isFunction( params ) ) {
36 // We assume that it's the callback
40 // Otherwise, build a param string
41 } else if ( params && typeof params === "object" ) {
45 // If we have elements to modify, make the request
46 if ( self.length > 0 ) {
50 // If "type" variable is undefined, then "GET" method will be used.
51 // Make value of this field explicit since
52 // user can override it through ajaxSetup method
56 } ).done( function( responseText ) {
58 // Save response for use in complete callback
63 // If a selector was specified, locate the right elements in a dummy div
64 // Exclude scripts to avoid IE 'Permission Denied' errors
65 jQuery( "<div>" ).append( jQuery.parseHTML( responseText ) ).find( selector ) :
67 // Otherwise use the full result
70 // If the request succeeds, this function gets "data", "status", "jqXHR"
71 // but they are ignored because response was set above.
72 // If it fails, this function gets "jqXHR", "status", "error"
73 } ).always( callback && function( jqXHR, status ) {
74 self.each( function() {
75 callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] );