Blame view
app/bower_components/jquery/src/ajax/load.js
1.83 KB
87c93a029
|
1 |
define( [ |
f986e111b
|
2 |
"../core", |
87c93a029
|
3 |
"../core/stripAndCollapse", |
f986e111b
|
4 5 6 7 |
"../core/parseHTML", "../ajax", "../traversing", "../manipulation", |
87c93a029
|
8 9 |
"../selector" ], function( jQuery, stripAndCollapse ) { |
f986e111b
|
10 |
|
87c93a029
|
11 |
"use strict"; |
f986e111b
|
12 13 14 15 16 |
/** * Load a url into a page */ jQuery.fn.load = function( url, params, callback ) { |
87c93a029
|
17 |
var selector, type, response, |
f986e111b
|
18 |
self = this, |
87c93a029
|
19 |
off = url.indexOf( " " ); |
f986e111b
|
20 |
|
87c93a029
|
21 22 |
if ( off > -1 ) { selector = stripAndCollapse( url.slice( off ) ); |
f986e111b
|
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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 ) { |
87c93a029
|
40 |
jQuery.ajax( { |
f986e111b
|
41 |
url: url, |
87c93a029
|
42 43 44 45 |
// If "type" variable is undefined, then "GET" method will be used. // Make value of this field explicit since // user can override it through ajaxSetup method type: type || "GET", |
f986e111b
|
46 47 |
dataType: "html", data: params |
87c93a029
|
48 |
} ).done( function( responseText ) { |
f986e111b
|
49 50 51 52 53 54 55 56 |
// 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 |
87c93a029
|
57 |
jQuery( "<div>" ).append( jQuery.parseHTML( responseText ) ).find( selector ) : |
f986e111b
|
58 59 60 |
// Otherwise use the full result responseText ); |
87c93a029
|
61 62 63 64 65 66 67 68 |
// If the request succeeds, this function gets "data", "status", "jqXHR" // but they are ignored because response was set above. // If it fails, this function gets "jqXHR", "status", "error" } ).always( callback && function( jqXHR, status ) { self.each( function() { callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] ); } ); } ); |
f986e111b
|
69 70 71 72 |
} return this; }; |
87c93a029
|
73 |
} ); |