在Ajax Jquery函数中添加if else函数 [英] Add if else function in Ajax Jquery function
本文介绍了在Ajax Jquery函数中添加if else函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在我的JS中像这样添加其他功能:?
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>");
}
或者您的意思是这样:
$.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>");
}
});
这篇关于在Ajax Jquery函数中添加if else函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文