views:

288

answers:

4

I'm working on some old AJAX code, written in the dark dark days before jQuery. Strangely, it has been working fine for years, until today when it suddenly stopped firing its callback. Here's the basic code:

var xml = new XMLHttpRequest();  // only needs to support Firefox
xml.open("GET", myRequestURL, true);
xml.onreadystatechange = function() { alert ('test'); };
xml.send(null);

Checking the Firebug console, the request is being sent with no worries, and it is receiving the correct XML from the request URL, but the onreadystatechange function is not working at all. There's no javascript errors or anything else strange happening in the system.

I wish I could just rewrite everything using jQuery, but I don't have the time right now. What could possibly be causing this problem??


A further update - I've been able to test my code in a different browser (FFx 3.0) and it was working there, so it must be a problem with my browser. I'm running Firefox 3.5b4 on Vista, and I've tried it now with all my addons disabled with no luck. It's still really bugging me because I was working on this site yesterday (with the same browser setup) and there were no problems at all...

Actually I just took a look back in my Addons window and saw that Firebug was still enabled. If I disable Firebug, it works perfectly. If I enable it, it's broken. Firebug version 1.40.a31

A: 

It seems unlikely that onreadystatechange would stop working. Is it possible that the 'alert' function has somehow been disabled or overridden? Can you replace the alert with some code to make a visible change in the page, and check its functionality that way? (I know, its a stretch, but it just seems so strange that onreadystatechange wouldn't work!)

Bruce
yeah, i've tried putting alert("foo") on the line before the onreadystatechange and that works fine.
nickf
if onreadystatechange wasn't working, I think the web would collapse. maybe the XmlHttpRequest object is being deleted or aborted before the response comes back? Is there more to the repro code, or is what you show the whole thing? Maybe your firefox installation is corrupt? *grin*
Bruce
if the domain requested was not found, there would not be a state change, but there *should* be an error thrown
Jonathan Fingland
+4  A: 

is the url malformed? have you tried putting the whole thing in a try-catch and alerting the errors (if any)

is it failing on an authorization check? does the url in question require http-auth? (though there should be state changes in this case, I'll admit)

edit:

I have a really funny thought here. Are you using firefox 3.5 beta4? I develop a firefox extension for a browser-based game and recently discovered some odd behvaviour. With my extension or firebug observing the ajax requests made from the page, the script ccreating them would never get calledback. The request would be correctly observed and processed by both firebug and my extension (I could observe what was sent and received)... but the page itself would never hear from the request again -- like it had disappeared into a black hole.

Try turning off firebug (or at least turn off listening to 'Net' for that domain) and test it again

Jonathan Fingland
+3  A: 

Known Firefox bug affecting Firebug; see http://code.google.com/p/fbug/issues/detail?id=1569&q=xhr&colspec=ID%20Type%20Status%20Owner%20Test%20Summary for details :-)

NickFitz