Problem with open Ajax function in google chrome 28.0.1500.72 and later

I think I found a problem when the ajax open functions do not work properly in google chrome after updating version 28.0.1500.72. This problem was originally detected using the embedded web server as a server, but I was also able to reproduce it on the apache web server.

The problem occurs when I call ajaxObject.open ("GET", "URL", true). This usually works, but sometimes the client computer that runs javascript will not issue a GET request for the URL (this was confirmed with wirehark). At this point, ajaxObject.readyState changes from 1 to 2 to 4, as if it had sent the request correctly and received a response. This problem has not previously occurred with Chrome, and it is not an IE or firefox problem. Interestingly, on a successful call, ajaxObject.readyState goes from 1, to 2, to 3, to 4.

We hard-coded the headers on the embedded web server so as not to cache the requested page retrieved using ajax, since we need to request the page again and again and update its contents. To duplicate this function on apache, I added:

<FilesMatch ".(shtml|html|js|css)$"> Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" Header set Pragma "no-cache" </FilesMatch> 

to the httdp-conf file.

Below is the html page where I can reproduce the problem.

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> <html> <head> <script type="text/javascript"> function newAjaxObject() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support Javascript/AJAX! Please upgrade your browser."); return null; } } } return xmlHttp; } function getStatus() { var ajaxStatus = newAjaxObject(); ajaxStatus.onreadystatechange=function() { if(ajaxStatus.readyState==4) { eval('var tester =' + ajaxStatus.responseText); queueStatusUpdate(); } } ajaxStatus.open("GET","status.shtml",true); ajaxStatus.send(null); } // Wait 'timeDelay' milliseconds before requesting an update var timeDelay = 100; function queueStatusUpdate() { setTimeout('getStatus()',timeDelay); } </script> </head> <body onload="queueStatusUpdate();"> </body> </html> 

This is the response text that should be on the status.shtml page:

 {"status":"Valid Data"} 

working breakpointworking request

Using the Network tab in the chrome debugger, go to the page and click Refresh until you see that it stops requesting status.shtml and an error occurs.

no request sentbreakpoint with status 0

I believe this is a problem with Chrome, but I thought I would post it here before posting it as an error for them just in case I miss something simple.

Also, changing the asynchronous request to a synchronous request fixes the problem, but this is not the route I want to take.

Thanks!

+4
source share
1 answer

I encountered the same Chrome error and I was able to confirm it using your code. The workaround I found was to add a random parameter to the URL (something like? Rand = XYZ to make the URL unique) and simply repeat the original AJAX request with the new URL.

Based on my testing, here is some information that might be useful:

  • I was able to reproduce the error in the latest stable version of Chrome: 28.0.1500.95

  • I was able to reproduce the error in the Windows version. I also tested the same version of Chrome on OSX, and I could not play it there.

  • The error appears when the AJAX request is interrupted, leaving the page, and then saved throughout the life of this tab (therefore, it is important to refresh the test page before the error appears). As soon as the request fails, all future requests for this resource on the same tab will fail, even if the page is reloaded.

+2
source

Source: https://habr.com/ru/post/1494586/


All Articles