After looking into w3schools tutorial of AJAX I discovered that the below script works fine in Firefox with the time updating on keyup but in IE, it'll update once and thats it.
PHP Code:
<html> <body>
<script type="text/javascript"> function ajaxFunction() { var xmlHttp; try { xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari } catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.myForm.time.value=xmlHttp.responseText; } } xmlHttp.open("GET","time.php",true); xmlHttp.send(null);
} </script>
<form name="myForm"> Name: <input type="text" onkeyup="ajaxFunction();" name="username" /> Time: <input type="text" name="time" /> </form>
</body> </html>
Looking on other websites that use AJAX such as Youtube and Google Labs the scripts they use to achieve cross-browser functionality are veeeerry long and way beyond my current meagre understanding of Javascript.
What methods do you use to get AJAX to work cross-browser and if at all, how could this script be edited to achieve that?
Edit: Oh, and using 'POST' doesn't help. Before you say
Edit2: Editing my headers not to allow caching didn't do anything
Edit3: Nor did using this bit of code instead:
var url = "time.php?ms=" + new Date().getTime();
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
Last edited by Petsmacker; 12-17-2007 at 08:35 PM..
|