I have this js code
$(".new_milestone").validate({
submitHandler: function(form) {
$(form).submitWithAjax();
},
errorPlacement: function(error, element) {
error.insertBefore(element);
}
});
It all works, errorPlacement and the submitWithAjax function. But when I post the form the second time without reloading the page, the form gets posted two times. Next time 3 times and so on.
When I do this
$(".new_milestone").validate({
errorPlacement: function(error, element) {
error.insertBefore(element);
}
});
$(".new_milestone").submitWithAjax();
It works, but it does the ajax post even if the form is not valid.
The submitWithAjax function looks like this (thanks Ryan Bates)
jQuery.fn.submitWithAjax = function() {
this.submit(function() {
$.post(this.action, $(this).serialize(), null, "script");
$('.spinning').show();
$("#dialog_form").dialog("close")
return false;
})
return this;
};
Any ideas on stopping this behavior?