parse json in jquery
$.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]
alert(data.the_result)
will display false
in your example, or whatever the value of the_result
is generally.
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".
I think your success function should look like this:
function(data){
alert(data.the_result);
return;
}
try this:
alert(JSON.stringify(data));
then you'll be able to see that data as you want to.
精彩评论