I have bind an event on submit form on a login page. I want to make an ajax request first before form submission. Problem is that ajax post dont work, as form submits very early.... If on event add on end "return false" ajax works but this way form dont submits, how delay a bit execution so ajax end and after continue form submission?
This way ajax dont work:
$("button").bind("click", function(){
$.post("test.php", $(this).parents("form").serialize());
})
This way ajax works but form dont submits:
$("button").bind("click", function(){
$.post("test.php", $(this).parents("form").serialize());
return false;
})
You could wait for the ajax to finish before submiting the form:
$("button").bind("click", function() {
var form = $(this).parents("form");
$.post("test.php", form.serialize(), function() {
form.submit();
});
return false;
})