【问题标题】:TransactionScope and Ajax call returning error responseTransactionScope 和 Ajax 调用返回错误响应
【发布时间】:2018-10-09 05:15:31
【问题描述】:

我有一个调用特定方法的 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 调用直到事务范围完成其操作?

【问题讨论】:

    标签: ajax entity-framework model-view-controller transactionscope


    【解决方案1】:

    jquery Ajax async true 默认工作。

    http://api.jquery.com/jquery.ajax/

    用async false等待响应,我觉得用signalR更准确

    【讨论】:

    • 我也用过,但没用。恰好在 1 分钟后得到相同的错误。
    • @user10476550 使用signalR,这样让客户端等待服务器端的长进程是不对的
    猜你喜欢
    • 2019-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-15
    • 2017-05-27
    • 1970-01-01
    • 2017-08-05
    • 2011-10-27
    相关资源
    最近更新 更多