I can not figure out why the following AJAX code will only load the information from my php page one time in IE, works in all other browsers with no problem.
<script type="text/javascript">
var c=0;
function randomize(str)
{
if (str=="")
{
document.getElementById("dispeople").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("dispeople").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","randomize.php?q=" + Math.random(),false);
xmlhttp.send();
document.getElementById('txt').value=c;
c=c+1;
}
setInterval( "randomize()", 2000 );
</script>
I am fairly new to using AJAX and have researched this issue and implemented all the solutions I could find, any help would be greatly appreciated.
Update, 10/21/2011
I have checked out JQuery and implemented it and am still experiencing the same issue if anyone has any suggestions here is the code I am currently using:
<script type="text/javascript">
var c=0;
$.ajaxSetup ({
// Disable caching of AJAX responses
cache: false
});
setInterval(function() {
$.ajax({
type: "GET",
url: 'randomize.php?ck=' + (new Date()).getTime(),
cache: false,
success: function(data) {
$('#dispeople').html(data);
}
});
},2000);
</script>
Thank you