0

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

2
  • i get [Object object] also if I write object.toString() Commented May 3, 2012 at 11:22
  • I mean, what is the error that is returned. You should be able to see it in the console. Alerting [Object object] is not indicative of an error in your javascript. Commented May 3, 2012 at 11:37

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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 ?

2 Comments

input has no id, but only name.
You missed the quotes around the selector - amended for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.