简体   繁体   English

ASP response.redirect不重定向

[英]Asp response.redirect not redirecting

I have a Login popup form where I send ajax post request to Login.asp script to prevent go to POST URL after submit. 我有一个“登录”弹出式表单,在该表单中我将ajax发布请求发送到Login.asp脚本,以防止提交后进入POST URL。

<script>

$(function() {
    $('#contactForm').submit(function(e){
        e.preventDefault();

        $.ajax({
            url:'/ASPLogin/Login.asp',
            type:'POST',
            data:$('#contactForm').serialize(),
            dataType:'text',
            success: function(response)
            {
            var temp = new Array();
            temp = response.split("|");

            if (temp[0] == 'something') {

              }
              else {

                  $("#response").html(response);
             }
            }
        });

    });
});

</script>

in Login.asp 在Login.asp中

If OK Then
 response.redirect("/index.asp?token=" & str)
Else
 response.write("error")
End If

So when login is wrong I put Error message into popup form, if login is OK then I need to close popup form and redirect. 因此,当登录错误时,我将错误消息放入弹出窗口,如果登录正常,则需要关闭弹出窗口并重定向。

But I get redirected page sources inside my popup form. 但是我在弹出表单中重定向了页面源。

I tried to do like that 我试图那样做

If OK Then
 response.write("<script>$('#closeBut').click();</script>")
 response.redirect("/index.asp?token=" & str)
Else
 response.write("error")
End If

Popup is closed but page is no redirected 弹出窗口已关闭,但页面未重定向

I tried to do like that 我试图那样做

If OK Then
 response.write("<script>$('#closeBut').click();</script>")
 Response.Write("<script>window.location.href = " & "'/index.asp?token=" & str & "';</script>")
Else
 response.write("error")
End If

Popup is closed but page is no redirected 弹出窗口已关闭,但页面未重定向

How to fix that? 如何解决? How to close popup and redirect page normally? 如何正常关闭弹出窗口和重定向页面?

The server side redirection won't affect the browser itself when the request is made from ajax, only the ajax request object will see the redirected page source in the response. 当从ajax发出请求时,服务器端重定向不会影响浏览器本身,只有ajax请求对象才能在响应中看到重定向的页面源。

You need to response.write the url so that you can make a client-side redirection 您需要response.write url,以便可以进行客户端重定向

For example: 例如:

If OK Then
 response.write("/index.asp?token=" & str)
Else
 response.write("error")
End If

then in the ajax success event: 然后在ajax成功事件中:

success: function(response)
{

    if (response != 'error') {
        location.href = response;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM