Is it possible to add other else function in my JS like this: ?
if response == success redirect to home
if response == failed redirect to failed
$.ajax({
type: "POST",
url: action,
data: form_data,
success: function(response) {
if (response == 'success')
window.location.replace("home");
else
$("#message").html("<div class='error_log'><p class='error'>Invalid username and/or password.</p></div>");
}
});
success: function(response) {
if (response == 'success')
window.location.replace("home");
else if (response == "failed")
window.location.replace("failed");
else
$("#message").html("<div class='error_log'><p class='error'>Invalid username and/or password.</p></div>");
}
Or you meant this:
$.ajax({
type: "POST",
url: action,
data: form_data,
error: function() {
window.location.replace("Failed");
},
success: function(response) {
if (response == 'success')
window.location.replace("home");
else
$("#message").html("<div class='error_log'><p class='error'>Invalid username and/or password.</p></div>");
}
});
Use this:
$.ajax({
type: "POST",
url: action,
data: form_data,
success: function(response)
{
if (response == 'success')
window.location.replace("home");
else if (response == 'failure')
{
$("#message").html("<div class='error_log'><p class='error'>Invalid username and/or password.</p></div>");
window.location.replace("failed");
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With