this is my form:
<form name="Aform" method="post" action="test.php" id="Aform">
this is my script:
var validator = $("#Aform").validate({
...
// form.submit(); <-- it works
form.submit(function() {
$.post($(this).attr("action"), $(this).serialize(), function(data) {
$.colorbox({html:data});
},
'html');
return false;
});
// <-- it does not work
Have you looked at your JS console to see if you are generating any errors? Have you verified that your POST request is successful and returns data?
It looks to me that this code only runs once the submit event has happened (making an assumption about the code not shown). Then you defined another event handler, but then that handler is never fired because the submit event does not happen again.
Calling
form.submit()fires the submit event, callingform.submit(function(){})defines an event handler but does not fire the submit event.You could call
form.submit()after you define the event handler, but defining an event handler and immediately invoking it is just jumping through an unnecessary hoop. You could do this instead: