开发者

How to parse json data in jquery ajax success?

info = {
  开发者_开发知识库  'phone_number': '123456',
    'personal_detail': {'foo': foo, 'bar': bar},
    'is_active': 1,
    'document_detail': {'baz': baz, 'saz': saz},
    'is_admin': 1,
    'email': 'foo@bar.com'
}

return HttpResponse(
    simplejson.dumps({'success':'True', 'result':info}),
    mimetype='application/javascript')


if(data["success"] === "True") {
    alert(data[**here I want to display personal_detail and document_details**]);
}

How can I do this?


May be you are looking for jquery parse json, if I understand the question properly.


$.getJSON('/ajax_url/',
    {
        'some_data': 'Some Value'
    },
    function(result){
        alert(result.personal_detail.foo);
    }
);

$.getJSON sends a GET request to the provided url (first argument) with urlencoded params (second argument) you provide, and on success, calls the success function (third argument) with the JSON decoded result from the server (result).

This is a shortcut version of using $.ajax and manually calling $.parseJSON, etc.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜