服务器重定向公共共享功能

时间:2017-11-30 16:06:31

标签: ajax vb.net redirect

我正在为这个java脚本发生一个ajax调用。

<System.Web.Services.WebMethod()>
    Public Shared Function Finalize()
        try
             Sendemail1()
             sendemail2()
             doesomething()
        Catch ex As Exception
            ErrorMSg = -1
            Throw ex
        Finally
            con.Close()
            con.Dispose()
        End Try
      Return "success"
    End Function

如果成功,那么我将其交给客户端,并希望将页面重定向到另一个页面。但我不知道为什么系统永远不会达到成功:或错误:或完成:Ajax调用。如果我删除所有三个内部公共共享功能,那么它按预期工作。

Public Shared Function Sendemail1()
    '''' Send email
End Function

Public Shared Function Sendemail2()
   '''' Send email
End Function

Public Shared Function doesomething()
 '''' Update database
End Function

正如我解释的那样,我希望在完成所有功能后重定向到不同的页面。我累了加入

HttpContext.Current.Response.Redirect("MyPage.aspx")

在第三个公共共享功能结束时,重定向没有发生。

我还尝试在主Ajax调用中调用第三个函数后添加,但仍然没有发生。

我在这里遗漏了什么。解决此问题的正确方法是什么。

客户端代码:

<script type = 'text/javascript'>
$(document).ready(function () {
var userConfirmation = window.confirm('Are you sure?\nPress OK to continue.\nPress CANCEL to stop the process.'); 
    if (userConfirmation == false) { 
    return 0;
    }
    else { 
             $.ajax
                 ({
                     type: 'POST',
                     //url: 'NewSubmission.aspx/function1',
                     url: 'NewSubmission.aspx/FinalizeSub',
                     data: JSON.stringify({ id:193, SubType:1, Exception:0, PageNum:12, Authors:1 }),
                     //data: '{sessionval: '' + data1 + '' }',
                     contentType: 'application/json; charset=utf-8',
                     dataType: 'json',
                     success: OnSuccess,
                     failure: function (response) {
                         alert(response.d);
                     },
                     Error: function (response) {
                         alert(response.d);
                     },
                    Complete: function (response) {
                         alert(response.d);
                     }


                 }); 

     function OnSuccess(data) {
    alert(data.d);
  /// Redirection will heppen here
}

 } 
});
</script>

PS:我也没有在浏览器控制台上看到错误消息。

0 个答案:

没有答案