我有一些(可能)长时间运行的ajax调用,如果用户导航到另一个页面,我想中止.以下jQuery代码在导航离开页面时调用所有挂起的XMLHttpRequest对象的中止:
$.ajaxSetup({
beforeSend: function(xhr) {
$(window).bind('beforeunload', function() {
xhr.abort();
});
}
});
Run Code Online (Sandbox Code Playgroud)
在测试用例中,我强制在被调用的服务器端操作上等待10秒.使用Firebug,我确认上面的代码确实导致所有挂起的ajax调用在我单击页面上的任何链接时立即停止.但是,浏览器仍然等待整整10秒,然后再转到下一页.IE似乎表现出相同的行为.这是一个已知的浏览器行为吗?在这种情况下,我能做些什么让用户立即离开页面?提前致谢.
这是我的环境:Win 7上的IIS7.5,.NET 4,App Pool Integrated
web.config中
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
</configuration>
Run Code Online (Sandbox Code Playgroud)
Test.aspx文件
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void OnAction(object sender, EventArgs e)
{
int count;
status.Text = (int.TryParse(status.Text, out count) ? count + 1 : 0).ToString();
Session["test"] = count;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>IIS Session Hang Test</title>
<script>
var mutiPostback = function () {
var e = document.getElementById('LinkButton1');
e.click();
e.click();
};
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:ScriptManager runat="server" ID="SM">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" …Run Code Online (Sandbox Code Playgroud) internet-explorer iis-7 session-state integrated-pipeline-mode
我有一个运行在IIS 7中的asp.net 4.0网站。从几天前开始,很多请求都停留在RequestAquireState中。
您是否知道我可以从哪里开始寻找解决问题的方法?在我的代码中?在IIS中?您是否遇到过这样的事情?
