X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fajax%2Fajax.js;h=0b965e4a1628bbde8f67f3b18e686d2af359e47e;hb=a5dbcaf67579b2266b64ffbdd2a328d180f7f64b;hp=1426604bd73909a80a4cfce7602eb68c0dd3f41f;hpb=08d865862a0d26f8ca616ff5a39d97203bda9614;p=jquery.git
diff --git a/src/ajax/ajax.js b/src/ajax/ajax.js
index 1426604..0b965e4 100644
--- a/src/ajax/ajax.js
+++ b/src/ajax/ajax.js
@@ -4,17 +4,18 @@ jQuery.fn.extend({
* Load HTML from a remote file and inject it into the DOM, only if it's
* been modified by the server.
*
- * @example $("#feeds").loadIfModified("feeds.html")
+ * @example $("#feeds").loadIfModified("feeds.html");
* @before
* @result 45 feeds found.
*
* @name loadIfModified
* @type jQuery
* @param String url The URL of the HTML file to load.
- * @param Hash params A set of key/value pairs that will be sent to the server.
- * @param Function callback A function to be executed whenever the data is loaded.
- * @cat AJAX
+ * @param Map params (optional) Key/value pairs that will be sent to the server.
+ * @param Function callback (optional) A function to be executed whenever the data is loaded (parameters: responseText, status and response itself).
+ * @cat Ajax
*/
+ // DEPRECATED
loadIfModified: function( url, params, callback ) {
this.load( url, params, callback, 1 );
},
@@ -22,126 +23,138 @@ jQuery.fn.extend({
/**
* Load HTML from a remote file and inject it into the DOM.
*
- * @example $("#feeds").load("feeds.html")
+ * Note: Avoid to use this to load scripts, instead use $.getScript.
+ * IE strips script tags when there aren't any other characters in front of it.
+ *
+ * @example $("#feeds").load("feeds.html");
* @before
* @result 45 feeds found.
*
* @example $("#feeds").load("feeds.html",
- * {test: true},
- * function() { alert("load is done"); }
+ * {limit: 25},
+ * function() { alert("The last 25 entries in the feed have been loaded"); }
* );
* @desc Same as above, but with an additional parameter
* and a callback that is executed when the data was loaded.
*
- * @test stop();
- * $('#first').load("data/name.php", function() {
- * ok( $('#first').text() == 'ERROR', 'Check if content was injected into the DOM' );
- * start();
- * });
- *
* @name load
* @type jQuery
* @param String url The URL of the HTML file to load.
- * @param Hash params A set of key/value pairs that will be sent to the server.
- * @param Function callback A function to be executed whenever the data is loaded.
- * @cat AJAX
+ * @param Object params (optional) A set of key/value pairs that will be sent as data to the server.
+ * @param Function callback (optional) A function to be executed whenever the data is loaded (parameters: responseText, status and response itself).
+ * @cat Ajax
*/
load: function( url, params, callback, ifModified ) {
- if ( url.constructor == Function )
+ if ( jQuery.isFunction( url ) )
return this.bind("load", url);
-
+
+ var off = url.indexOf(" ");
+ if ( off >= 0 ) {
+ var selector = url.slice(off, url.length);
+ url = url.slice(0, off);
+ }
+
callback = callback || function(){};
-
+
// Default to a GET request
var type = "GET";
-
+
// If the second parameter was provided
- if ( params ) {
+ if ( params )
// If it's a function
- if ( params.constructor == Function ) {
+ if ( jQuery.isFunction( params ) ) {
// We assume that it's the callback
callback = params;
params = null;
-
+
// Otherwise, build a param string
} else {
params = jQuery.param( params );
type = "POST";
}
- }
-
+
var self = this;
-
+
// Request the remote document
- jQuery.ajax( type, url, params,function(res, status){
-
- if ( status == "success" || !ifModified && status == "notmodified" ) {
- // Inject the HTML into all the matched elements
- self.html(res.responseText).each( callback, [res.responseText, status] );
-
- // Execute all the scripts inside of the newly-injected HTML
- $("script", self).each(function(){
- if ( this.src )
- $.getScript( this.src );
- else
- eval.call( window, this.text || this.textContent || this.innerHTML || "" );
- });
- } else
- callback.apply( self, [res.responseText, status] );
-
- }, ifModified);
-
+ jQuery.ajax({
+ url: url,
+ type: type,
+ data: params,
+ ifModified: ifModified,
+ complete: function(res, status){
+ // If successful, inject the HTML into all the matched elements
+ if ( status == "success" || !ifModified && status == "notmodified" )
+ // See if a selector was specified
+ self.html( selector ?
+ // Create a dummy div to hold the results
+ jQuery("")
+ // inject the contents of the document in, removing the scripts
+ // to avoid any 'Permission Denied' errors in IE
+ .append(res.responseText.replace(/