导航离开页面时,jquery.ajax()返回错误

时间:2016-07-01 02:39:34

标签: jquery asp.net ajax

我正在使用var liste2= liste1.Where((x,i)=> !liste1.Skip(i+1).Any(s=>s.SequenceEqual(x))); window.onbeforeunload与用户确认他是否真的希望离开某个页面。当用户使用jquery.ajax()方法在对话框中选择“Leave”选项时,我在服务器端调用页面方法来执行一些数据库簿记。 但我对Page方法的window.onunload返回错误。从其他javascript函数调用时,它按预期工作。 这是我正在使用的片段。

在Page.aspx

jquery.ajax()

另外,我正在设置

 function confirmExit() {
    console.log('In ConfirmExit function unlock='+unlock+'needsave='+needSave);
            timeout = setTimeout(function() {
            }, 1000);
        return "You have pending changes on this request";

        }
        function unloadPage(){
        console.log('In Unload Page function unlock= '+unlock+'needsave= '+needSave);
            if (needSave && unlock) {
                UnlockRequest(null);
                return "You have pending changes on this request";
            }
            clearTimeout(timeout);
        }
Page.aspx中的

。 这是我在解锁方法中对服务器的ajax调用

 window.onbeforeunload = confirmExit;
 window.onunload = unloadPage;

Page.aspx.cs中的服务器方法

dataString = "{'reqID' :'" + selectedVal + "'}";
            var url = "Page.aspx/UnLockRequest";
            console.log('Calling Unlock Request from Unlock Method');
            jQuery.ajax({
                type: 'POST',
                url: url,
                data: dataString,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                processData: 'false',
                success: function () {
                    var r = $("#MainContent_btnSubmit")
                    r.prop('disabled', true);
                    var r = $("#MainContent_releaseLockButton")
                    r.prop('disabled', true);
                    r = $("#MainContent_Button2")
                    r.prop('disabled', true);
                    if ($('#RequestLockedDiv').get(0) !== null)
                        $('#RequestLockedDiv').get(0).setAttribute("style", "display:none;");
                    needSave = unlock = false;
                    $(document).stopIdleTimeoutPlugin();
                    //window.location.reload(false);
                }
            });

我无法在浏览器的“网络”选项卡和fiddler中看到此服务器请求。 BTW我正在使用Chrome进行测试和ASP.NET 4.0。 我错过了什么。

0 个答案:

没有答案
相关问题