View Full Version : AJAX works in IE, but not firefox

07-06-2006, 05:51 PM
I'm having some problems trying to get an AJAX script of mine to work. The script works just fine in IE, but does not work in firefox. I've been playing around with the script, and my guess is it is the "onreadystatechange" test that is not working. But I'm not sure how to fix it.

The script calls a PHP file which returns a number based on the value of the selection in a <select> tag.

<title>First Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">

function createXMLRequest() {
if (typeof XMLHttpRequest != "undefined") {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
var aVersions = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","Microsoft.XMLHttp" ];
for (var i = 0; i < aVersions.length; i++) {
try {
var xmlHttp = new ActiveXObject(aVersions[i]);
return xmlHttp;
} catch (oError) {
//Do nothing
throw new Error("XMLHttp object could be created.");

<script type="text/javascript">

function getRating2(airport) {

var xmlHttp = createXMLRequest();
var file = "test.php?a=" + airport;
xmlHttp.open ('get',file,true);
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readystate == "4" || xmlHttp.readyState=="complete") {
document.getElementById('test').innerHTML = xmlHttp.responseText;




<select onChange="getRating2(this.value)">
<option value="">---None---</option>
<option value="DTW">Detroit Metro</option>
<option value="YIP">Willow Run</option>
<option value="ARB">Ann Arbor</option>
<option value="DET">Detroit City</option>

<div id="test"></div>


Any input would be greatly appreciated, this is my very first AJAX script.



07-06-2006, 05:58 PM
Did not really look at the code. Are you getting an error message in the JavaScript console in Firefox? Hade you added debug statements to see where it dies?


07-06-2006, 06:08 PM
I get a syntax error in the console. But it does not tell me where to look for it.

07-06-2006, 06:30 PM
think you need to check you capitilization of readyState and ALSO it returns a number and not a string. You should also be checking the status code to make sure you are getting 200.


07-07-2006, 07:45 PM
Thanks for your help! It's working just fine now.