Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Ajax stops working in Chrome after few iterations

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.

like image 230
aVC Avatar asked Aug 18 '13 21:08

aVC


2 Answers

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.

like image 147
aVC Avatar answered Oct 13 '22 10:10

aVC


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

like image 22
kol Avatar answered Oct 13 '22 09:10

kol