My ajax success/failure event is not firing. I am using jquery validation and inside that i am using ajax for form submit. My forms are getting submitted but return value(JSON data) is not showing as described in AJAX.
I tried to use alert() but it is also not firing.
<script type="text/javascript">
$('document').ready(function()
{
$("#alert-form").validate({
ignore: '',
messages: {
select2Start: {
required: "Please select your starting point.",
}
},
//});
submitHandler: function(form) {
e.preventDefault;
var btn = $('#publish');
btn.button('loading');
alert('valid form submission');
$.ajax({
type: 'post',
url:$('form#alert-form').attr('action'),
cache: false,
dataType: 'json',
data: $('form#alert-form').serialize(),
beforeSend: function() {
$("#validation-errors_alert").hide().empty();
},
success: function(data) {
if(data.success == false)
{
var arr = data.errors;
$.each(arr, function(index, value)
{
if (value.length != 0)
{
$("#validation-errors_alert").append('<div class="alert alert-danger"><strong>'+ value +'</strong><div>');
}
});
$("#validation-errors_alert").show();
btn.button('reset');
}else{
// alert("Job Alert Configured successfully.");
$("#job_success_alert").append('<div class="alert alert-success"><strong>Alert Configured successfully.</strong><div>');
}
},
error: function(xhr, textStatus, thrownError) {
alert('Something went to wrong.Please Try again later...');
alert(thrownError);
btn.button('reset');
}
});
return false;
}
});
});
</script>