pindol
pindol

Reputation: 2110

jquery ajax return error object

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

Upvotes: 0

Views: 6086

Answers (2)

Satya
Satya

Reputation: 8881

change this

data: 'mail_to='+ $('input[name$="email"]').val()+'&new_password='+new_password,

to

data: 'mail_to='+ $("#email").val()+'&new_password='+new_password,

and it should work

can you add the id to it ?

Upvotes: 0

sofl
sofl

Reputation: 1024

In case you wanna halt your script until the request is complete, u should use async:false. http://jsfiddle.net/Z8sRF/

Upvotes: 2

Related Questions