Thanks for the code Klaus. Nice idea... When I tried this, the ajax call worked but the xhr.onreadystatechange is 'undefined' so I cannot do anything with it. (I got the samer error when trying to use a function in the 'beforeSend' ajax argument.)
Does Jquery definitely return the XMLHTTP object? Or something else? Cheers, George Klaus Hartl wrote: > > George Adamson schrieb: >> Hi folks, >> >> Anyone know if it is possible to add a custom event handler for the >> onreadystatechange events of JQuery AJAX calls? >> >> I'm accessing a url that is slow to complete but does add to its output >> as >> it progresses. >> It would be nice to be able to catch each new fragment to inform the user >> of >> progress. >> >> I've experimented with the 'beforeSend' ajax argument to fiddle with the >> XMLHttpRequest object's properties before making the ajax call but had no >> luck. >> >> Many thanks, >> >> George > > $.ajax returns the XmlHttpRequest object, thus you can do: > > var xhr = $.ajax({ ... }); > xhr._cachedOnreadystatechange = xhr.onreadystatechange; > xhr.onreadystatechange = function() { > xhr._cachedOnreadystatechange(); > // do something else > }; > > > -- Klaus > > > _______________________________________________ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > > -- View this message in context: http://www.nabble.com/Can-you-add-event-handler-to-XMLHttpRequest.onreadystatechange--tf3270003.html#a9107770 Sent from the JQuery mailing list archive at Nabble.com. _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/