X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax%2Fajax.js;h=dd54d0c30f7c455399ee2731f5c816312848e40a;hb=f28f199dc0a353135ef8b9afa2f3d25c6ffd2c75;hp=a0e64629477e3820cfb1fa9a50a5226ba14e4fcd;hpb=327bfb88a2ea85a9a30e5f5a1687d9ac399aa3f1;p=jquery.git
diff --git a/src/ajax/ajax.js b/src/ajax/ajax.js
index a0e6462..dd54d0c 100644
--- a/src/ajax/ajax.js
+++ b/src/ajax/ajax.js
@@ -1,564 +1,390 @@
-// AJAX Plugin
-// Docs Here:
-// http://jquery.com/docs/ajax/
-
-/**
- * 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")
- * @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
- */
-jQuery.fn.loadIfModified = function( url, params, callback ) {
- this.load( url, params, callback, 1 );
-};
-
-/**
- * Load HTML from a remote file and inject it into the DOM.
- *
- * @example $("#feeds").load("feeds.html")
- * @before
- * @result 45 feeds found.
- *
- * @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
- */
-jQuery.fn.load = function( url, params, callback, ifModified ) {
- if ( url.constructor == Function )
- return this.bind("load", url);
-
- callback = callback || function(){};
-
- // Default to a GET request
- var type = "GET";
-
- // If the second parameter was provided
- if ( params ) {
- // If it's a function
- if ( params.constructor == Function ) {
- // We assume that it's the callback
- callback = params;
- params = null;
-
- // Otherwise, build a param string
- } else {
- params = jQuery.param( params );
- type = "POST";
+jQuery.fn.extend({
+ load: function( url, params, callback ) {
+ 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 it's a 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({
+ url: url,
+ type: type,
+ data: params,
+ complete: function(res, status){
+ // If successful, inject the HTML into all the matched elements
+ if ( status == "success" || 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(/