Web Hosting Talk







View Full Version : XMLHTTPRequest


c0rl0
10-25-2005, 01:00 PM
Hey everyone,

I'm sort of new to the whole AJAX thing as far as using the XMLHTTPRequest object. Anyway, I've been doing some toying around with it and wrote a little script (php) which models a alphabetic search. The gist is that you have a list of "customers" by last name and you enter your first letter and it narrows it down to the people who match, and so on...

Anyway, it works perfectly in IE but I'm having some problems with FireFox. The very first letter that is typed doesn't want to work properly in FireFox. It works if you backup to that letter, but if you type that letter in to the blank input box it just doesn't work. I know that the script isn't the most efficient right now but I'm just starting out basic here and seeing what this stuff can do. I'm nowhere near close to putting any of this in production...

Running script:
coriowebsolutions.com/shawn/ajax/test.php

Source:
coriowebsolutions.com/shawn/ajax/test.txt
coriowebsolutions.com/shawn/ajax/getMatchingCustomers.txt

After doing a bit of debugging I noticed that it's sending 2 HTTP Requests eventhough it should only be sending 1. Not sure how to fix it though. Any help on this would be appreciated, as I'm close to giving up! =]

Thanks...
Shawn

zoldar
10-26-2005, 08:01 AM
Well, I can't help you much, because I've just started learning
about XMLhttp.

There is nice toolkit for AJAX called CPAINT:

http://cpaint.sourceforge.net/

And one more thing - browser detection code that You are using
isn't too sure. It'd be better if you tested that certain objects
exist, for example:


ro = false;

// branch for native XMLHttpRequest object
if(window.XMLHttpRequest) {
try {
ro = new XMLHttpRequest();
} catch(e) {
ro = false;
}
// branch for IE/Windows ActiveX version
} else if(window.ActiveXObject) {
try {
ro = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
ro = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
ro = false;
}
}
}
if(ro) {
// further XMLhttp related code goes here
}


It's a bit modified example from page:

http://developer.apple.com/internet/webcontent/xmlhttpreq.html