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.

<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

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 tryed 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 tryed 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?


Source: ajax

Leave a Reply