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

Nag*_*tak 0 ajax jquery

是否有可能在我的JS中添加其他功能:

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

$.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>");
    }
});?
Run Code Online (Sandbox Code Playgroud)

gdo*_*ica 6

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>");
}?
Run Code Online (Sandbox Code Playgroud)

或者你的意思是:

$.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>");
    }
});?  
Run Code Online (Sandbox Code Playgroud)