这是我的AJAX ...
$.ajax({
url: "../getSynd.php",
dataType:"json",
success: function(jsVar){
document.write(jsVar['sysinfo'][0]);
syndStatus("canvas1", "first server name", "76","red");
syndStatus("canvas2", "second server name", "1.2423","green");
}
});
来自getSynd.php的我的JSON如下......
[{"sysinfo":"server1","result":"1.17805935"},{"sysinfo":"server2","result":"2069.59799893"}]
如何从jsVar中获取sysinfo / result?
编辑: 我想通了,谢谢大家!
$.ajax({
url: "../getSynd.php",
dataType:"json",
success: function(jsVar){
syndStatus("canvas1", jsVar[0]['sysinfo'], jsVar[0]['result']);
syndStatus("canvas1", jsVar[1]['sysinfo'], jsVar[1]['result']);
}
});
答案 0 :(得分:2)
由于您已经在ajax中使用了dataType
param,因此您将获得已经解析为javascript变量的响应。您只需要在成功回调ajax调用时捕获它,如下所示:
$.ajax({
url: '...',
dataType: 'json',
success: function(jsVar) {
//jsVar will be the javascript array
}
});