Ajax call canceled by browser

I am using the JS prototype Framework to make Ajax calls. Here is my code:

new Ajax.Request( '/myurl.php', {method: 'post', postBody: 'id='+id+'&v='+foo, onSuccess: success, onFailure: failed} ); function success(ret) { console.log("success",ret.readyState, ret.status); } function failed(ret) { console.log("failed",ret.readyState, ret.status); } 

In most cases, this works fine, and the success function is called with a status code of 200. At about 5% of the time in Safari, the success function is called with a status code of 0. In this case, when I look at the Network tab of the web inspector, the ajax call is indicated with status canceled. I can confirm with the server logs that the request never hit the server. It is as if the ajax request was immediately canceled without even trying to connect to the server. I have not found a reliable way to reproduce this, it seems random. I do this 20 times, and this happens once.

Does anyone know what will cause the ajax call to be canceled or status code 0 to be returned?

+6
source share
2 answers

The reason may be the combination of the http server and the browser you are using. This does not seem to be a PrototypeJS library error.

Several sources claim that the keep-alive parameter of the HTTP connection appears to be broken in Safari (see here , here or here ). At Apache, they recommend adding this to the configuration:

 BrowserMatch "Safari" nokeepalive 

(Please check the appropriate syntax in the server documentation).

If Safari does not handle HTTP persistent connections to your server well, this may explain what you are experiencing.

If this is not too difficult for you, I would try a different HTTP server, there are many available in each OS.

We do not have enough information to fully answer your answer. The problem with the server is leadership, but there may be others. It would be nice to know if it does the same in other browsers (Firefox with Firebug will display such information, Chrome, Opera and IE have built-in development toolbars). Another right question is how often do you execute this AJAX request per second (if necessary).

+1
source

I know this is an old topic, but I would like to share a solution for Safari that can save a little. The following line really solved all the problems:

 BrowserMatch "^(?=.*Safari)(?=.*Macintosh)(?!.*Chrom).*" nokeepalive gzip-only-text/html 

The regular expression ensures that only Safari is detected on the Mac, not Mobile Safari and Chrome (ium), etc. Safari for Windows also doesn't match, but the keepalive issue seems to be a combination of Mac-Safari. In addition, some versions of Safari cannot handle gzipped css / js.

All our symptoms of our site or CSS crashes were not completely loaded into different versions of Safari, because of which I almost pulled my hair out (Safari is the new IE) were solved for us using this Apache hacker.

0
source

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


All Articles