@@ -158,72 +158,63 @@ jQuery.fn.extend({
158
158
load : function ( url , params , callback ) {
159
159
if ( typeof url !== "string" && _load ) {
160
160
return _load . apply ( this , arguments ) ;
161
+ }
161
162
162
163
// Don't do a request if no elements are being requested
163
- } else if ( ! this . length ) {
164
+ if ( ! this . length ) {
164
165
return this ;
165
166
}
166
167
167
- var off = url . indexOf ( " " ) ;
168
+ var selector , type ,
169
+ self = this ,
170
+ off = url . indexOf ( " " ) ;
171
+
168
172
if ( off >= 0 ) {
169
- var selector = url . slice ( off , url . length ) ;
173
+ selector = url . slice ( off , url . length ) ;
170
174
url = url . slice ( 0 , off ) ;
171
175
}
172
176
173
- // Default to a GET request
174
- var type = "GET" ;
177
+ // If it's a function
178
+ if ( jQuery . isFunction ( params ) ) {
175
179
176
- // If the second parameter was provided
177
- if ( params ) {
178
- // If it's a function
179
- if ( jQuery . isFunction ( params ) ) {
180
- // We assume that it's the callback
181
- callback = params ;
182
- params = undefined ;
180
+ // We assume that it's the callback
181
+ callback = params ;
182
+ params = undefined ;
183
183
184
- // Otherwise, build a param string
185
- } else if ( typeof params === "object" ) {
186
- type = "POST" ;
187
- }
184
+ // Otherwise, build a param string
185
+ } else if ( typeof params === "object" ) {
186
+ type = "POST" ;
188
187
}
189
188
190
- var self = this ;
191
-
192
189
// Request the remote document
193
190
jQuery . ajax ( {
194
191
url : url ,
192
+
193
+ // if "type" variable is undefined, then "GET" method will be used
195
194
type : type ,
196
195
dataType : "html" ,
197
- data : params ,
198
- // Complete callback (responseText is used internally)
199
- complete : function ( jqXHR , status , responseText ) {
200
- // Store the response as specified by the jqXHR object
201
- responseText = jqXHR . responseText ;
202
- // If successful, inject the HTML into all the matched elements
203
- if ( jqXHR . isResolved ( ) ) {
204
- // #4825: Get the actual response in case
205
- // a dataFilter is present in ajaxSettings
206
- jqXHR . done ( function ( r ) {
207
- responseText = r ;
208
- } ) ;
209
- // See if a selector was specified
210
- self . html ( selector ?
211
- // Create a dummy div to hold the results
212
- jQuery ( "<div>" )
213
- // inject the contents of the document in, removing the scripts
214
- // to avoid any 'Permission Denied' errors in IE
215
- . append ( responseText . replace ( rscript , "" ) )
216
-
217
- // Locate the specified elements
218
- . find ( selector ) :
219
-
220
- // If not, just inject the full result
221
- responseText ) ;
222
- }
196
+ data : params
197
+ } ) . done ( function ( responseText ) {
223
198
224
- if ( callback ) {
225
- self . each ( callback , [ responseText , status , jqXHR ] ) ;
226
- }
199
+ // See if a selector was specified
200
+ self . html ( selector ?
201
+
202
+ // Create a dummy div to hold the results
203
+ jQuery ( "<div>" )
204
+
205
+ // inject the contents of the document in, removing the scripts
206
+ // to avoid any 'Permission Denied' errors in IE
207
+ . append ( responseText . replace ( rscript , "" ) )
208
+
209
+ // Locate the specified elements
210
+ . find ( selector ) :
211
+
212
+ // If not, just inject the full result
213
+ responseText ) ;
214
+
215
+ } ) . always ( function ( ) {
216
+ if ( callback ) {
217
+ self . each ( callback , arguments ) ;
227
218
}
228
219
} ) ;
229
220
0 commit comments