Reputation: 2344
I am breaking my head on an embedded project: Microchip ethernet/ wifi. I have a webpage where the data is loaded via ajax. Due to size limits, I am not using jquery, just Javascript AJAX.
PROBLEM: It seems to be all good in firefox. But in Chrome, It starts, and If I refresh, the AJAX stops working (sometimes, after repeated refreshes). No error is logged in the console.
I created a stripped down demo on
pastebin.com/test4/ajaxTest.html. It uses just the mchp.js
from the microchip demo. The page loads a number from another page via AJAX. This is repeated 100 ms, and If I cant get anything in 5 seconds ( ie ~50 attempts), it times out.
To recreate this error
, open the demo link in Chrome, and keep refreshing. I have a time out of 5 seconds. I am using latest version of Chrome
. Appreciate any hints. Thanks.
NOTE: Once it breaks, even if i keep refreshing, it wont work. but if I close the tab and open a new one, it works.
Upvotes: 5
Views: 3906
Reputation: 1
function getXMLHTTP() { //function to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e){
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getdef()
{
alert('str');
if (str=="")
{
document.getElementById("def1").innerHTML="";
return;
}
if (window.XMLHttpRequest)
Upvotes: 0
Reputation: 28698
WireShark shows that after a while, your AJAX code gets HTTP/1.1 304 Not Modified
instead of HTTP/1.1 200 OK
. I think the answer gets cached by Chrome. You could append a random number argument to the URL to prevent caching (see here).
Upvotes: 2
Reputation: 2344
Thanks to @kol, figured it was a cache issue. So I have modified the url with a random number in the argument. Seems to be working now.
Upvotes: 3