I need to do an ajax request to a php file when form is submitted, using jquery. I write this code:
$.ajax({
type: 'POST',
url: 'send_password.php',
data: 'mail_to='+ $('input[name$="email"]').val()+'&new_password='+new_password,
success: function(response){
alert(response);
},
error: function(r){
alert(r);
return false;
}
});
The problem is that this function return error, so i get an alert message, that contains “[Object object]” message and the form go to the action page and doesn’t stop, like it doesn’t see return false line (after alert(r)).
How can I do?
Thanks, Mattia
In case you wanna halt your script until the request is complete, u should use async:false. http://jsfiddle.net/Z8sRF/