<html>
<body>
<script type="text/javascript">
function ajaxFunction() {
var xmlHttp;
try { //Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e) {
try { //Internet Explorer
xmlHttp = new ActiveXObject("Msxml2.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.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>
And in time.php:
Code:
<?php
echo date("H:i:s");
?>
And it works perfectly fine, the first time. But the second time and the rest of the times (after clearing the textboxes), the same time as before will continue to pop up, each time I release a key. But it should be the current time, not the same time as before! I would really appreciate some help here. What in my code is wrong? Or is it IE 7 that troubles me?
I think (but if i'm thinking wrong, correct me) that IE caches the result, so it's always the same.
this is a classical problem, that can be avoided by passing a random useless parameter, or a datetime, so that IE thinks that you're requesting something new, and it avoids to cache the result.
I think (but if i'm thinking wrong, correct me) that IE caches the result, so it's always the same.
this is a classical problem, that can be avoided by passing a random useless parameter, or a datetime, so that IE thinks that you're requesting something new, and it avoids to cache the result.
Wow, thanks! That worked! I just added a junk-counter and added it to the the adress as a GET-variable. Do you know of some way to tell IE to reload the page anyway or maybe to clear that specific history so it will be reloaded?
I've got the exact same problem in IE, except adding a random number to the url isnt helping, any ideas?
How random is the random number? (I haven't used that random generator before, I believe, if it isn't the same as in the C/C++ math library) could it maybe have happened that the rendom generator used the same random seed all the times?
Just taking a shot, try adding a counter instead as I did, there could be a chans that helps.
alien51 had it - it was the ordering of open onreadystatechange and send, that'll teach me to grab code from w3schools rather than walking up to my pc and getting my own
A bunch of people complain about that issue with the W3Schools code. A bunch of pople have sent them emails telling them to change it, but they never did.
Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]