| @@ 10603-10665 (lines=63) @@ | ||
| 10600 | /** |
|
| 10601 | * Load a url into a page |
|
| 10602 | */ |
|
| 10603 | jQuery.fn.load = function( url, params, callback ) { |
|
| 10604 | if ( typeof url !== "string" && _load ) { |
|
| 10605 | return _load.apply( this, arguments ); |
|
| 10606 | } |
|
| 10607 | ||
| 10608 | var selector, type, response, |
|
| 10609 | self = this, |
|
| 10610 | off = url.indexOf( " " ); |
|
| 10611 | ||
| 10612 | if ( off > -1 ) { |
|
| 10613 | selector = jQuery.trim( url.slice( off, url.length ) ); |
|
| 10614 | url = url.slice( 0, off ); |
|
| 10615 | } |
|
| 10616 | ||
| 10617 | // If it's a function |
|
| 10618 | if ( jQuery.isFunction( params ) ) { |
|
| 10619 | ||
| 10620 | // We assume that it's the callback |
|
| 10621 | callback = params; |
|
| 10622 | params = undefined; |
|
| 10623 | ||
| 10624 | // Otherwise, build a param string |
|
| 10625 | } else if ( params && typeof params === "object" ) { |
|
| 10626 | type = "POST"; |
|
| 10627 | } |
|
| 10628 | ||
| 10629 | // If we have elements to modify, make the request |
|
| 10630 | if ( self.length > 0 ) { |
|
| 10631 | jQuery.ajax( { |
|
| 10632 | url: url, |
|
| 10633 | ||
| 10634 | // If "type" variable is undefined, then "GET" method will be used. |
|
| 10635 | // Make value of this field explicit since |
|
| 10636 | // user can override it through ajaxSetup method |
|
| 10637 | type: type || "GET", |
|
| 10638 | dataType: "html", |
|
| 10639 | data: params |
|
| 10640 | } ).done( function( responseText ) { |
|
| 10641 | ||
| 10642 | // Save response for use in complete callback |
|
| 10643 | response = arguments; |
|
| 10644 | ||
| 10645 | self.html( selector ? |
|
| 10646 | ||
| 10647 | // If a selector was specified, locate the right elements in a dummy div |
|
| 10648 | // Exclude scripts to avoid IE 'Permission Denied' errors |
|
| 10649 | jQuery( "<div>" ).append( jQuery.parseHTML( responseText ) ).find( selector ) : |
|
| 10650 | ||
| 10651 | // Otherwise use the full result |
|
| 10652 | responseText ); |
|
| 10653 | ||
| 10654 | // If the request succeeds, this function gets "data", "status", "jqXHR" |
|
| 10655 | // but they are ignored because response was set above. |
|
| 10656 | // If it fails, this function gets "jqXHR", "status", "error" |
|
| 10657 | } ).always( callback && function( jqXHR, status ) { |
|
| 10658 | self.each( function() { |
|
| 10659 | callback.apply( self, response || [ jqXHR.responseText, status, jqXHR ] ); |
|
| 10660 | } ); |
|
| 10661 | } ); |
|
| 10662 | } |
|
| 10663 | ||
| 10664 | return this; |
|
| 10665 | }; |
|
| 10666 | ||
| 10667 | ||
| 10668 | ||
| @@ 9411-9473 (lines=63) @@ | ||
| 9408 | /** |
|
| 9409 | * Load a url into a page |
|
| 9410 | */ |
|
| 9411 | jQuery.fn.load = function( url, params, callback ) { |
|
| 9412 | if ( typeof url !== "string" && _load ) { |
|
| 9413 | return _load.apply( this, arguments ); |
|
| 9414 | } |
|
| 9415 | ||
| 9416 | var selector, type, response, |
|
| 9417 | self = this, |
|
| 9418 | off = url.indexOf( " " ); |
|
| 9419 | ||
| 9420 | if ( off > -1 ) { |
|
| 9421 | selector = jQuery.trim( url.slice( off ) ); |
|
| 9422 | url = url.slice( 0, off ); |
|
| 9423 | } |
|
| 9424 | ||
| 9425 | // If it's a function |
|
| 9426 | if ( jQuery.isFunction( params ) ) { |
|
| 9427 | ||
| 9428 | // We assume that it's the callback |
|
| 9429 | callback = params; |
|
| 9430 | params = undefined; |
|
| 9431 | ||
| 9432 | // Otherwise, build a param string |
|
| 9433 | } else if ( params && typeof params === "object" ) { |
|
| 9434 | type = "POST"; |
|
| 9435 | } |
|
| 9436 | ||
| 9437 | // If we have elements to modify, make the request |
|
| 9438 | if ( self.length > 0 ) { |
|
| 9439 | jQuery.ajax( { |
|
| 9440 | url: url, |
|
| 9441 | ||
| 9442 | // If "type" variable is undefined, then "GET" method will be used. |
|
| 9443 | // Make value of this field explicit since |
|
| 9444 | // user can override it through ajaxSetup method |
|
| 9445 | type: type || "GET", |
|
| 9446 | dataType: "html", |
|
| 9447 | data: params |
|
| 9448 | } ).done( function( responseText ) { |
|
| 9449 | ||
| 9450 | // Save response for use in complete callback |
|
| 9451 | response = arguments; |
|
| 9452 | ||
| 9453 | self.html( selector ? |
|
| 9454 | ||
| 9455 | // If a selector was specified, locate the right elements in a dummy div |
|
| 9456 | // Exclude scripts to avoid IE 'Permission Denied' errors |
|
| 9457 | jQuery( "<div>" ).append( jQuery.parseHTML( responseText ) ).find( selector ) : |
|
| 9458 | ||
| 9459 | // Otherwise use the full result |
|
| 9460 | responseText ); |
|
| 9461 | ||
| 9462 | // If the request succeeds, this function gets "data", "status", "jqXHR" |
|
| 9463 | // but they are ignored because response was set above. |
|
| 9464 | // If it fails, this function gets "jqXHR", "status", "error" |
|
| 9465 | } ).always( callback && function( jqXHR, status ) { |
|
| 9466 | self.each( function() { |
|
| 9467 | callback.apply( self, response || [ jqXHR.responseText, status, jqXHR ] ); |
|
| 9468 | } ); |
|
| 9469 | } ); |
|
| 9470 | } |
|
| 9471 | ||
| 9472 | return this; |
|
| 9473 | }; |
|
| 9474 | ||
| 9475 | ||
| 9476 | ||