我有一个Ajax调用,它调用一个特定的方法。
$.ajax({
url: '@Url.Action("ExcelDataUpload", "ProjectDefinition")',
type: "POST",
headers: { "cache-control": "no-cache" },
//data: { XLTransactionType: xltranstype, FilePath: filepath },
data: { XLTransactionType: xltranstype, ExcelUploadData: exceljsonData },
cache: false,
success: function (data) {
if (data != null && data.StatusID == 1) {
ShowMessage(1, data.Message);
}
else {
ShowMessage(0, data.Message);
}
},
error: function (data) {
ShowMessage(0, "Upload is not successful.Please try again!!!");
}
});在此方法内部,使用事务作用域执行操作
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, TimeSpan.FromHours(1))) {
try {
using (objDb = new UPDEntities()) { }
}
if(id > 0) {
scope.Complete();
} else {
scope.Dispose();
}
}这需要3-4分钟才能完成,但在Ajax调用完成之前,它总是返回错误消息,如果数据较少,则返回成功。如何暂停Ajax调用,直到事务作用域完成其操作?
发布于 2018-10-09 22:03:46
jquery Ajax async true在默认情况下有效。
http://api.jquery.com/jquery.ajax/
使用async false等待响应,我认为使用signalR更准确
https://stackoverflow.com/questions/52713777
复制相似问题