Arb*_*æde 7 javascript jquery internet-explorer jquery-ui asp.net-mvc-3
我在IE 8-9中得到了以下坚持的JS问题,在其他浏览器中,我的代码工作得非常好.
案例:我在JS中有以下代码,它应该启动一些服务器进程并更新进度条,其中包含服务器端的状态,Jquery UI提供的内容:
$("#btnSendUser").click(function (event) {
$.ajax({
type: "POST",
url: "/StartLongProcess",
dataType: "json",
traditional: true,
data: { userIds: users },
success: function (result) {
console.log("Process start");
}
});
var processId = 0;
getStatus(processId);
});
function getStatus(processId) {
var url = '/GetStatus';
$.get(url, { clientProcessId: processId }, function (data) {
if (!data.IsDone) {
$("#progress").progressbar({ value: data.Progress });
window.setTimeout("getStatus(" + processId + ")", 350);
}
else {
$("#progress").progressbar({ value: 100 });
console.log("Done");
};
});
}
Run Code Online (Sandbox Code Playgroud)
在当前控制器的StartLongProcess方法中,我以这种方式启动长服务器进程:
[ValidateInput(false)]
public void StartLongProcess(Guid[] userIds)
{
...
var processTask = new LongProcess(MesssageService.Email.SendMails);
processTask.BeginInvoke(service.LongProcess(userIds), new AsyncCallback(EndSendingProcess), processTask);
}
Run Code Online (Sandbox Code Playgroud)
读取当前状态的方法是下一个:
/// <summary>
/// Gets the current progress.
/// </summary>
/// <param name="id">The id.</param>
public JsonResult GetCurrentProgress(int clientProcessId)
{
ControllerContext.HttpContext.Response.AddHeader("cache-control", "no-cache");
var currentProgress = MesssageService.Email.GetCurrentLog(clientProcessId);
return Json(currentProgress ?? new LogMessage(0), JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
我在Chrome和FF中测试了这段代码,在那些浏览器中,进度条和进程始终正确完成.但是在IE 8-9中,看起来getStatus函数无法以这种方式调用.这是真的吗?为所有浏览器实现任务的最佳方法是什么?谢谢.
@cleric 可以随时尝试
\n\nwindow.setTimeout(function() {getStatus(processId)},350);\nRun Code Online (Sandbox Code Playgroud)\n\n而不是
\n\nwindow.setTimeout("getStatus(" + processId + ")", 350);\nRun Code Online (Sandbox Code Playgroud)\n\n。\xe2\x80\x93 安东尼·格里斯特 一月 18 日 22:50
\n