假设您的服务器端脚本未设置正确的
Content-Type: application/json响应标头,则需要使用
dataType:'json'参数向jQuery指示这是JSON 。
然后,您可以使用该
$.each()函数遍历数据:
$.ajax({ type: 'GET', url: 'http://example/functions.php', data: { get_param: 'value' }, dataType: 'json', success: function (data) { $.each(data, function(index, element) { $('body').append($('<div>', { text: element.name })); }); }});或使用
$.getJSON方法:
$.getJSON('/functions.php', { get_param: 'value' }, function(data) { $.each(data, function(index, element) { $('body').append($('<div>', { text: element.name })); });});


