Reset AJAX Requests
Posted on 2006-06-30
I'm building a simple AJAX search field for a buy/sell tickets website I've been developing for a client. Users can enter city, state, venue, artist, and event date in the search field. As they type it behaves very much like Google Suggest, giving recommedations for what they're typing. When they're finished typing, after waiting for a second or two, it will send the data and update the <div> on the right with search results.
The problem that I'm coming across is that if I try to change too many fields at once (keep in mind, each one may call an AJAX request), it gets confused, or overflows, or blows up, or something--in any case the AJAX requests just stop working. It works perfectly as long as I don't try to move too fast. Ideally, I'd like to prevent this altogether, so that it *always* works, but if that's not really plausible, then I'd at least like a "Search" button users can press that will forcibly reset all AJAX requests, and then send whatever data's been entered. I tried to implement this already, but it doesn't seem to work.
To create the XMLHttpRequest object, I used this code that I found in "Rasmus' 30-second AJAX tutorial":
if ( navigator.appName == 'Microsoft Internet Explorer' )
ro = new ActiveXObject('Microsoft.XMLHTTP');
ro = new XMLHttpRequest();
var http = createRequestObject();
And on the "Search" button, like I said, I tried to add some code that would force it to absolutely reset all requests, but it's not working--if you update the fields too fast, it freezes up, and this code isn't enough to unfreeze it.
http = createRequestObject();
I can send you a link to a working example of what I've got if you'd like to see it, but I can assure you that there's *a lot* of code, so I don't know if you really want to sift through all of it.