我有 jQuery AJAX 调用,该调用请求来自 WEB API 服务的摘要计数。WEB API 处理请求并调用存储过程(sql server)传递请求参数。存储过程需要更长的时间(超过 10 分钟来处理请求。如果存储过程需要超过 10 分钟,jQuery AJAX 调用将报告状态代码为 12002 或 12152 的未知错误(这些错误与连接问题有关),但Web服务器在10分钟后从存储过程中收到结果。问题出现在浏览器上是IE8.0,IE9.0,firefox,但chrome即使等待超过10分钟也收到响应。有什么解决方案可以保留服务器和客户端之间的通信活动。我尝试将连接请求标头从 ajax 更改为“关闭”、“打开” “保持活力”没有任何作用。请帮帮我。
Java 脚本代码。
$.ajax({
type: "post",
url: URLPrefix + 'api/querydispatcher/summary',
data: s,
success: function (data) {
window.clearInterval(int);
$('#wait').hide();
$('#CancelSummary').hide();
$('#backgroundmodal').hide();
$("#tResultTotals").slideDown('slow');
DeserializeJSon(eval(data));
if (!CancelSummaryRequest) {
CancelSummaryRequest = true;
$('#DownloadDetailedReport').show();
}
else {
$('#tResultTotals').hide();
}
},
$('#wait').hide();
$('#CancelSummary').hide();
$('#backgroundmodal').hide();
error_Dialog(request.responseText);
}
});
}
Server Side (WEB API) code.
[WebInvoke(UriTemplate = "summary", Method = "POST")]
public List<QueryResult> GetSummaryReport_Queue(JsonValue SummaryXML)
{
MyContext db = new MyContext();
DateTime StartTime = DateTime.Now;
string sumXML = SummaryXML["XMLJson"].ToString().Replace(@"\", "").Replace(@"""", "");
//These are two codes created by JSon @ the end of the String that need to be trim off.
sumXML = sumXML.Replace("u000du000a", "");
List<QueryResult> results = null;
XElement xxml = XElement.Parse(sumXML);
string ReportID = xxml.Descendants("ReportId").FirstOrDefault().Value;
string err = "";
try
{
results = db.fnReportResult(sumXML).ToList();
}
catch (Exception e)
{
err = e.Message + " : "+(e.InnerException!=null?e.InnerException.Message : "");
throw e;
}
finally {
///--- Record Audit Info.
double RunningTime = DateTime.Now.Subtract(StartTime).TotalMilliseconds;
string parameters = "ApplicationType:Query_Dispatcher" + "||User:" + SummaryXML["UserId"].ToString().Replace(@"\", "").Replace(@"""", "") +
"||Session:" + SummaryXML["Session"].ToString().Replace(@"\", "").Replace(@"""", "") +
"||Running Time:" + RunningTime.ToString() + "||Request Type:Summary Report" +
"||Report ID:" + ReportID +
"||Error:" + err;
Audit SaveAudit = new Audit();
SaveAudit.WriteAudit("Query_Builder", parameters);
//####-Recording Audit Info
}
return results;
}