gpt4 book ai didi

jquery - 在Ajax Jquery函数中添加if else函数

转载 作者:行者123 更新时间:2023-12-01 06:17:13 28 4
gpt4 key购买 nike

是否可以在我的 JS 中添加其他 else 函数,如下所示:?

如果响应==成功重定向到主页
如果响应==失败重定向到失败

$.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>");
}
});​

关于jquery - 在Ajax Jquery函数中添加if else函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12851839/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com