从Asp.Net中的Webmethod重定向

从Asp.Net中的Webmethod重定向,asp.net,web-services,web-applications,Asp.net,Web Services,Web Applications,我是Asp.Net编程新手,刚刚开始一个web项目。 我使用JSON从Aspx页面调用WebMethod,如下所示: <script type="text/javascript"> function getLogin() { var userName = document.getElementById('TextBox1').value; $.ajax({ type: "POST", url:

我是Asp.Net编程新手,刚刚开始一个web项目。 我使用JSON从Aspx页面调用WebMethod,如下所示:

 <script type="text/javascript">

    function getLogin() {
        var userName = document.getElementById('TextBox1').value;
        $.ajax({
            type: "POST",
            url: "Services/LogService.asmx/authenticateLogin",
            data: "{'userName':'" +userName.toString()+ "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
            alert(response.d)
            },
            error: function (xhr, status, error) {
                // alert(textStatus);
                DisplayError(xhr);
            }

        });
    }


function DisplayError(xhr) {
 var msg = JSON.parse(xhr.responseText);
 alert(msg.Message);  }
</script>
成功验证后,我想将用户重定向到另一个aspx页面

最佳做法是什么

谢谢
Samuel

getLogin()函数的成功部分添加重定向:

success: 
  function (response) {
    alert(response.d);
    windows.location.href = "http://url.for.redirect";
  }

(或用于jQuery/Javascript中的重定向)。

将重定向添加到
getLogin()函数的success部分:

success: 
  function (response) {
    alert(response.d);
    windows.location.href = "http://url.for.redirect";
  }
(或用于jQuery/Javascript中的重定向)。

在Ajax方法中

success: function(msg) {
      alert(response.d);
        window.location = "xyz.aspx";
  },
在Ajax方法中

success: function(msg) {
      alert(response.d);
        window.location = "xyz.aspx";
  },
我想这会对你有帮助


我认为这会对您有所帮助。

Ellis,重定向window.location.href或window.location.replace的用法?请参阅-它讨论了不同的选项及其优缺点。似乎更喜欢
replace
method.Ellis,重定向window.location.href或window.location.replace的用法?请参阅-它讨论了不同的选项及其优缺点。似乎更喜欢
replace
方法。