javascript - Issue with Ajax open function in google chrome 28.0.1500.72 and later -
i think found issue ajax open functions not behaving in google chrome after version 28.0.1500.72 update. issue found using embedded webserver server, have been able reproduce on apache webserver well.
the issue occurs when call ajaxobject.open("get","url",true). works, client pc running javascript not issue request url(this has been confirmed using wireshark). @ point ajaxobject.readystate changes 1 2 4 if sent request , received response. issue did not occur chrome previously, , not issue on ie or firefox. interestingly, on successful call, ajaxobject.readystate goes 1, 2, 3, 4.
we've hard coded headers on our embedded webserver not cache requested page fetched via ajax, need request page on , on again , refresh it's contents. duplicate functionality on apache, 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 httdp-conf file.
the following html page able reproduce issue on.
<!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 not support javascript/ajax! please upgrade 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 update var timedelay = 100; function queuestatusupdate() { settimeout('getstatus()',timedelay); } </script> </head> <body onload="queuestatusupdate();"> </body> </html>
this response text should in status.shtml page:
{"status":"valid data"}
using network tab in chrome debugger, navigate page , hit refresh until see stops requesting status.shtml , error has been thrown.
i believe issue chrome, thought i'd post here before submitting bug them in case missing simple.
also, changing asynchronous request synchronous request fixes issue, not route want take.
thanks !
i ran same chrome bug , able confirm code. workaround found append random parameter url (something ?rand=xyz, make url unique) , re-try original ajax request new url.
based on testing, here information might helpful:
i able reproduce bug on latest stable version of chrome: 28.0.1500.95
i able reproduce bug on windows version. tested same version of chrome on osx , unable reproduce there.
the bug appears when ajax request interrupted leaving page , persists entire life of tab (this why it's important refresh test page until bug shows up). once request fails, future requests resource in same tab fail, if page reloaded.
Comments
Post a Comment