X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax%2Fajax.js;h=ffe30481d37e956024115124454c52801b82f9eb;hb=f96bf1041553775a94c1034c97e253e350217173;hp=4ade2e846e687414e208f603e0816731a2b7356a;hpb=e7669f64d88612884df27c5744558191f8e6c8b1;p=jquery.git
diff --git a/src/ajax/ajax.js b/src/ajax/ajax.js
index 4ade2e8..ffe3048 100644
--- a/src/ajax/ajax.js
+++ b/src/ajax/ajax.js
@@ -1,819 +1,406 @@
jQuery.fn.extend({
+ load: function( url, params, callback ) {
+ if ( jQuery.isFunction( url ) )
+ return this.bind("load", url);
- /**
- * 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
- */
- loadIfModified: function( url, params, callback ) {
- this.load( url, params, callback, 1 );
- },
+ var off = url.indexOf(" ");
+ if ( off >= 0 ) {
+ var selector = url.slice(off, url.length);
+ url = url.slice(0, off);
+ }
- /**
- * Load HTML from a remote file and inject it into the DOM.
- *
- * @example $("#feeds").load("feeds.html")
- * @before
- * @result 45 feeds found.
- *
- * @example $("#feeds").load("feeds.html",
- * {test: true},
- * function() { alert("load is done"); }
- * );
- * @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();
- * });
- *
- * @test stop(); // check if load can be called with only url
- * $('#first').load("data/name.php");
- * $.get("data/name.php", function() {
- * ok( $('#first').text() == 'ERROR', 'Check if load works without callback');
- * start();
- * });
- *
- * @test stop();
- * foobar = undefined;
- * foo = undefined;
- * var verifyEvaluation = function() {
- * ok( foobar == "bar", 'Check if script src was evaluated after load' );
- * start();
- * };
- * $('#first').load('data/test.html', function() {
- * ok( $('#first').html().match(/^html text/), 'Check content after loading html' );
- * ok( foo == "foo", 'Check if script was evaluated after load' );
- * setTimeout(verifyEvaluation, 600);
- * });
- *
- * @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
- */
- 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 ( 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)
- // Execute all the scripts inside of the newly-injected HTML
- .evalScripts()
- // Execute callback
- .each( callback, [res.responseText, status] );
- } else
- callback.apply( self, [res.responseText, status] );
-
- }, ifModified);
-
+ 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(/