Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2006
    Posts
    152
    Thanks
    5
    Thanked 0 Times in 0 Posts

    AJAX works in IE, but not firefox

    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.

    Code:
    <html>
    <head>
    <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>
    <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;
    	}
    };
    xmlHttp.send(null);
    }
    
    </script>
    
    </head>
    
    <body>
    <form>
    
    	<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>
    	</select>
    
    </form>
    <div id="test"></div>
    
    </body>
    </html>
    Any input would be greatly appreciated, this is my very first AJAX script.

    Thanks,

    FuZion

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    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?

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Regular Coder
    Join Date
    May 2006
    Posts
    152
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I get a syntax error in the console. But it does not tell me where to look for it.

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    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.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #5
    Regular Coder
    Join Date
    May 2006
    Posts
    152
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thanks for your help! It's working just fine now.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •