簡體   English   中英

ASP response.redirect不重定向

[英]Asp response.redirect not redirecting

我有一個“登錄”彈出式表單,在該表單中我將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>

在Login.asp中

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

因此,當登錄錯誤時,我將錯誤消息放入彈出窗口,如果登錄正常,則需要關閉彈出窗口並重定向。

但是我在彈出表單中重定向了頁面源。

我試圖那樣做

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

彈出窗口已關閉,但頁面未重定向

我試圖那樣做

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

彈出窗口已關閉,但頁面未重定向

如何解決? 如何正常關閉彈出窗口和重定向頁面?

當從ajax發出請求時,服務器端重定向不會影響瀏覽器本身,只有ajax請求對象才能在響應中看到重定向的頁面源。

您需要response.write url,以便可以進行客戶端重定向

例如:

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

然后在ajax成功事件中:

success: function(response)
{

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM