weixin_33726318 2017-11-28 04:53 采纳率: 0%
浏览 56

jQuery Ajax错误不起作用

jQuery:

$.ajax({
    method: "POST",
    url: formsubmission,
    data: data,
    success: function() {
        alert("E-mail Sent");
        $("#submit").replaceWith('<button type="button" class="btn btn-primary" id="submit" onclick="send_email()">Submit</button>')
    }
    Error: function() {
        alert("E-mail Fail");
        $("#submit").replaceWith('<button type="button" class="btn btn-danger" id="submit" onclick="send_email()">Submit</button>')
    }
})

Anyone can please tell me Why Error function is not working? How can I resolve it?

  • 写回答

1条回答 默认 最新

  • 10.24 2017-11-28 06:13
    关注

    Change your code into this and check if you still have problem triggering the error function of your ajax call, and also instead of replacing the whole element in your error function, I removed the 'btn-primary' class and added 'btn-danger' class to make it shorter.

    $.ajax({
        method: "POST",
        url: formsubmission,
        data: data,
        success: function() {
            alert("E-mail Sent");
            $("#submit").replaceWith('<button type="button" class="btn btn-primary" id="submit" onclick="send_email()">Submit</button>')
        },
        error: function() {
            alert("E-mail Fail");
            $("#submit").removeClass('btn-primary').addClass('btn-danger');
        }
    });
    
    评论

报告相同问题?