我试图在使用此AJAX代码提交后显示成功或失败消息,但它无法正常工作。表单成功提交,但不显示消息。
我的代码:
$('#frm-create-vessel').on('submit', function (e) {
e.preventDefault();
var data = $(this).serialize();
var url = $(this).attr('action');
$.post(url, data, function (data) { //submit to table
if(data == true ){ //if the form submits successfully
$('#createvesselmessages').removeClass('hide').addClass('alert alert-success alert-dismissible').slideDown().show();
$('#createvesselmessages_content').html('<h4>Vessel Created Successfully</h4>');
$('#modal').modal('show');
$("#createvesselmessages").fadeOut(4000);
} else { //if the form fails
alert('false')
}
showVesselInfo(data.vessel_name);
});
$(this).trigger('reset');
})