Use alternative technique for triggering an abort, preventing an exception from being...
[jquery.git] / src / ajax.js
index 552d412..754de09 100644 (file)
@@ -45,18 +45,19 @@ jQuery.fn.extend({
                        }
                }
 
+               var self = this;
+
                // Request the remote document
                jQuery.ajax({
                        url: url,
                        type: type,
                        dataType: "html",
                        data: params,
-                       context:this,
                        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
-                                       this.html( selector ?
+                                       self.html( selector ?
                                                // Create a dummy div to hold the results
                                                jQuery("<div />")
                                                        // inject the contents of the document in, removing the scripts
@@ -71,7 +72,7 @@ jQuery.fn.extend({
                                }
 
                                if ( callback ) {
-                                       this.each( callback, [res.responseText, status, res] );
+                                       self.each( callback, [res.responseText, status, res] );
                                }
                        }
                });
@@ -391,7 +392,7 @@ jQuery.extend({
                // Wait for a response to come back
                var onreadystatechange = xhr.onreadystatechange = function( isTimeout ) {
                        // The request was aborted
-                       if ( !xhr || xhr.readyState === 0 ) {
+                       if ( !xhr || xhr.readyState === 0 || isTimeout === "abort" ) {
                                // Opera doesn't call onreadystatechange before this point
                                // so we simulate the call
                                if ( !requestDone ) {
@@ -457,12 +458,9 @@ jQuery.extend({
                        xhr.abort = function() {
                                if ( xhr ) {
                                        oldAbort.call( xhr );
-                                       if ( xhr ) {
-                                               xhr.readyState = 0;
-                                       }
                                }
 
-                               onreadystatechange();
+                               onreadystatechange( "abort" );
                        };
                } catch(e) { }