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?
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');
}
});