最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript Ajax stops working in Chrome after few iterations - Stack Overflow

programmeradmin2浏览0评论

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/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.

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./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.

Share Improve this question edited Feb 17, 2021 at 16:15 aVC asked Aug 18, 2013 at 21:11 aVCaVC 2,3443 gold badges25 silver badges47 bronze badges 3
  • 2 self inflicted ddos initiating in t-mius 5 minutes – Prisoner Commented Aug 18, 2013 at 22:40
  • I was able to free the "block" in the requests by running this mand in the JS console: xmlHttp = new XMLHttpRequest();xmlHttp.open("POST", 'ajaxXML.php', true);xmlHttp.send(''); After I did this a few seconds later it started working again. – Jack Cole Commented Aug 18, 2013 at 23:10
  • 4 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. Check out the accepted answer to this question: stackoverflow./questions/7432361/… – kol Commented Aug 18, 2013 at 23:19
Add a ment  | 

3 Answers 3

Reset to default 3

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.

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).

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)
发布评论

评论列表(0)

  1. 暂无评论