$.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
roger rover
6414 gold badges10 silver badges16 bronze badges
4 Answers 4
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
Dave Ward
60.7k14 gold badges119 silver badges134 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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
Erin
2,0582 gold badges16 silver badges26 bronze badges
Comments
I think your success function should look like this:
function(data){
alert(data.the_result);
return;
}
answered Aug 18, 2010 at 2:48
Mike G
4,8032 gold badges30 silver badges31 bronze badges
Comments
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
codersarepeople
2,0014 gold badges21 silver badges25 bronze badges
2 Comments
Hans Passant
Always painful to watch. Flip your post to CW to stem the downvote penalties.
codersarepeople
Sorry I'm sorta new here, what's CW? And why is mine so negative if it was accepted? lawl
lang-js
[object Object]instead of[object,object]?