Reputation: 2055
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 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?
Upvotes: 0
Views: 1243
Reputation: 1296
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.
You need to response.write the url so that you can make a client-side redirection
For example:
If OK Then
response.write("/index.asp?token=" & str)
Else
response.write("error")
End If
then in the ajax success event:
success: function(response)
{
if (response != 'error') {
location.href = response;
}
}
Upvotes: 2