异步Ajax请求锁定浏览器 [英] Asynchronous ajax request locking browser

查看:191
本文介绍了异步Ajax请求锁定浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是启动异步 ajax请求的简单代码段. 请求的处理时间故意较长(10秒或更长时间).

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

为什么浏览器阻止我的用户在异步请求过程中单击href链接? (已在Firefox和Chrome上试用)

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.

代码段:

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');

推荐答案

PHP是导致此问题的原因.当您执行session_start()时,PHP会锁定会话文件,因此不会同时写入该文件,并为正在运行的脚本提供对会话变量的完全访问权限(读取和写入).

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

因此,您需要尽快调用session_write_close().

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

这篇关于异步Ajax请求锁定浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆