tags:

views:

199

answers:

4
$.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]

+11  A: 

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

Dave Ward
+4  A: 

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".

download
that works! thanks
roger rover
A: 

try this:

alert(JSON.stringify(data));

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

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

I think your success function should look like this:

function(data){
  alert(data.the_result);
  return;
}
MikeG