以下是一个解决方案的示例:
$.ajax({ url: 'json_url', dataType: 'json', success: function(data) { $.each(data, function(key, value) { console.log(key + ': ' + value); }); }, error: function(jqXHR, textStatus, errorThrown) { console.log('Error: ' + textStatus + ' - ' + errorThrown); } });
确保dataType设置为json,以便正确解析响应。当成功时,$.ajax的success函数将data作为参数传递。在此示例中,数据是一个JSON对象。通过$.each遍历数据,可以使用其键值对。如果发生问题,则通过error函数进行处理。在此示例中,错误信息会在控制台中显示。
上一篇:Ajax成功函数和变量作用域