Hi,
I've come across an issue in jQuery 1.3.2 that was not in 1.2.6 that I
think may be a bug. If it's not a bug, I was just wondering under what
conditions that is required? The only thing that I could find in your
tickets that is similar is ticket #5114.
My issue is that I store an Ajax HTTP Request object for use by
javascript in a future user interaction after the success method is
executed for an Ajax call. When jQuery 1.3.2 was introduced, this
functionality stopped working. The root of the problem, I think, is
that the jQuery 1.3.2 command ".ajax" OnReadyStateChange function has
introduced a conditional block that if set calls an abort on the HTTP
Request object which erases the XML Response. The jQuery "ajax"
function sets up an OnReady State Change function in the variable
"onreadystatechange" with one parameter "isTimeout", which from the code
can be interpreted as a flag indicating that the callback was triggered
by a timeout function if the argument is a string with the value of
"timeout". In jQuery 1.3.2, this onreadystatechange function was
augmented to detect if a timeout had occurred and call the "abort"
method in the HTTP Request object. It does this by checking if the
variable "isTimeout" is set or not and not against the "timeout" string.
Since my Ajax calls are asynchronous calls, jQuery does not register the
onreadystate function with javascript's ajax on ready change callback
registration. Instead it uses "setInterval" to poll the current state
of the ajax call by registering the onreadystatechange function just
created as the callback to setInterval. I can't find any reference to
a callback of setInterval setting any arguments, thus when setInterval
fires and calls onreadystatechange function, the value of isTimeout is
some interger value that I don't know what it is referring too? Since
the abort condition blindly checks if "isTimeout" is set, which it is,
the abort is called and my object's variable which stores a reference to
that HTTP request object has it's objects state changed and the data
retrieved from a valid successful request erased. Since this abort is
called after the success function is run, the ajax response data is
consumed correctly and that instance of display is correct. Subsequent
use of that data is no longer valid.
I believe the correct code should be
if ( isTimeout == "timeout" )
xhr.abort();
because the "onreadystatechange" argument comes from either the
setInterval, or one of the calls below. In the asynchronous state, if
the timeout is set and the setTimeout setting expires, the function is
called with the string "timeout" and in the synchronous state, the
function is called with a NULL value.
3397: ajax: function( s ) {
...
// Wait for a response to come back
var onreadystatechange = function(isTimeout){
// The request was aborted, clear the interval
and decrement jQuery.active
if (xhr.readyState == 0) {
...
// The transfer is complete and the data is
available, or the request timed out
} else if ( !requestDone && xhr &&
(xhr.readyState == 4 || isTimeout == "timeout") ) {
requestDone = true;
// clear poll interval
if (ival) {
clearInterval(ival);
ival = null;
}
status = isTimeout == "timeout" ?
"timeout" :
!jQuery.httpSuccess( xhr ) ?
"error" :
s.ifModified &&
jQuery.httpNotModified( xhr, s.url ) ? "notmodified" :
"success";
...
// Fire the complete handlers
complete();
3609: if ( isTimeout )
xhr.abort();
// Stop memory leaks
if ( s.async )
xhr = null;
}
};
if ( s.async ) {
// don't attach the handler to the request, just
poll it instead
3620: var ival = setInterval(onreadystatechange, 13);
// Timeout checker
if ( s.timeout > 0 )
setTimeout(function(){
// Check to see if the request
is still happening
if ( xhr && !requestDone )
onreadystatechange(
"timeout" );
}, s.timeout);
}
...
// firefox 1.5 doesn't fire statechange for sync
requests
if ( !s.async )
onreadystatechange();
Thomas Poslinski
Synacor Inc.
--
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=.