0
$.ajax({
 url: 'contact',
 type: 'post',
 asynch: 'false', 
 dataType: 'json' ,
 data: "recaptcha_challenge_field=" + $("#recaptcha_challenge_field").val() + 
 "&recaptcha_response_field=" + $("#recaptcha_response_field").val() , 
 success: function(data) { 
 alert(data); 
 return;
 } 
 }); 

json reponse looks like this

{"the_result":"false"}

but alert(data) gives [object,object]

Noelkd
7,9272 gold badges35 silver badges45 bronze badges
asked Aug 18, 2010 at 2:39
1
  • Do you mean it gives [object Object] instead of [object,object]? Commented Aug 18, 2010 at 6:18

4 Answers 4

11

alert(data.the_result) will display false in your example, or whatever the value of the_result is generally.

answered Aug 18, 2010 at 2:43
Sign up to request clarification or add additional context in comments.

Comments

4

The response that you are getting is an Object. To display the data, you need to use:

alert(data.the_result);

or

alert(data["the_result"]);

If you just want the whole JSON string then just change the dataType to "text".

answered Aug 18, 2010 at 2:43

Comments

0

I think your success function should look like this:

function(data){
 alert(data.the_result);
 return;
}
answered Aug 18, 2010 at 2:48

Comments

-6

try this:

alert(JSON.stringify(data));

then you'll be able to see that data as you want to.

answered Aug 18, 2010 at 2:44

2 Comments

Always painful to watch. Flip your post to CW to stem the downvote penalties.
Sorry I'm sorta new here, what's CW? And why is mine so negative if it was accepted? lawl

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.