Asynchronous ajax request locking browser

十年热恋 提交于 2019-12-02 13:14:55

问题


This is a simple snippet of code to launch an aynchronous ajax request. The processing time of the request is deliberately long (10 seconds or more).

Why browser prevent my users to click on a href link during the process of the async request ? (tried with Firefox and Chrome)

The async request is normally called and the 'Ready' message is immediately displayed in console.

Snippet :

new Ajax.Request('index.php', {
    method: 'post',
    asynchronous: true,
    parameters: { 'sleep': 10 },
    onSuccess:  function(transport) { console.log('Success'); },
    onFailure: function() { console.log('Error'); }
});

console.log('Ready');

回答1:


PHP is the cause of the problem here. When you do session_start() the PHP locks the session file so there’s no concurrent writing to this file and gives the running script full access to the session variables ( reading and writing ).

So you need to call session_write_close() as soon as possible.



来源:https://stackoverflow.com/questions/26712449/asynchronous-ajax-request-locking-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!