Saturday, April 24, 2010

Ajax works on IE but not on Firefox - Newbie?

Tried to use ajax to show a string from html #2, but the code only works on IE and not on Firefox (nothing has came out, not even an error). The code is on a localhost (IIS). Below is the js code in the html #1 header.



%26lt;script type="text/javascript"%26gt;



function ajax_test() {



var obj = "test";



var server_page = "abc.htm"; //contains string only



var xmlhttp = false;



try {



//for javascript ver. %26gt; 5



xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");



} catch (e) {



//for older version



try {



xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");



} catch (E) {



//for non IE browsers



xmlhttp = false;



}



}



if (!xmlhttp %26amp;%26amp; typeof XMLHttpRequest != "undefined") {



xmlhttp = new XMLHttpRequest();



}



xmlhttp.open("GET", server_page);



xmlhttp.onreadystatechange = function() {



if (xmlhttp.readystate == 4 %26amp;%26amp; xmlhttp.status == 200) {



document.getElementById(obj).innerHTML = xmlhttp.responseText;



}



}



xmlhttp.send(null);



}



%26lt;/script%26gt;



Plz help



Ajax works on IE but not on Firefox - Newbie?windows vista ultimate





It looks good... anyway I'll change this fragment:



if (!xmlhttp %26amp;%26amp; window.XMLHttpRequest)



xmlhttp = new XMLHttpRequest();



When you are in these situations, try to put some alert('Debug message...') around, to be sure on what is really ran.



Ajax works on IE but not on Firefox - Newbie?default browser internet explorerThe problem has been solved. The solution is to replace xmlhttp.readystate with xmlhttp.readyState. Report It

No comments:

Post a Comment

 
web hosting providers