Flags and Lollipops

Sunday, January 14, 2007

onreadystatechange in Firefox

Just some Googleable info to save other people from banging their heads against a brick wall: I came across a weird bug in Firefox (2?)'s XMLHttpRequest implementation.

The onreadystatechange is, in theory, meant to fire whenever the ready state of the XMLHttpRequest object changes. The readystate goes (realistically) from 1 (loading request) to 4 (request complete). As you might expect, in practice different browsers have different behaviours.

Anyway, the bug: when loading one particular URL (using code very similar to this) only transition to state 1 was firing the onreadystatechange event. Using Firebug you could see the GET request going out and the correct data coming back, so the request was being fulfilled. With other URLs everything worked as it should.

The fix was to set up the onreadystate change handler after opening and sending.
http = new xmlhttprequest object, etc. etc.

http.open('get', editUrl);
http.send(null);
http.onreadystatechange = handleEditResponse();
Don't have a clue why...

Labels: , , ,

Comments and trackbacks Feel free to post your comments Anonymous Anonymous Anonymous Anonymous Anonymous LIMS/Bioinfo programmer Anonymous Anonymous . This post has trackbacks.


See all posts from: July 2005 August 2005 September 2005 October 2005 November 2005 December 2005 January 2006 February 2006 March 2006 April 2006 May 2006 June 2006 July 2006 September 2006 October 2006 November 2006 December 2006 January 2007 February 2007 March 2007 April 2007 May 2007 June 2007 July 2007 August 2007 October 2007 November 2007 December 2007 January 2008 February 2008 March 2008 April 2008