开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜