我要创建使用jQuery 1.4.2的AJAX应用程序,我已经用使用的get(),后()和阿贾克斯()方法本身尝试。我的PHP服务回报:
[{"k":"label0","v":0.5},{"k":"label1","v":99.43},{"k":"label2","v":2.46},{"k":"label3","v":46.29},{"status":"OK"}]在我成功的回调我试图访问的json.status和JSON [0] [0] 但它总是返回未定义。我究竟做错了什么?
函数getSysinfo(源){
VAR JSON = NULL;
$阿贾克斯({
网址:源,
键入:POST,
数据类型:JSON,
成功:功能(数据){
JSON =的eval((+数据+));
$('#数据)HTML(json.status);
警报(JSON [0] [0]);
refreshChart(JSON);
},
错误:函数(请求,状态,错误){
警报(请求:\ t+要求+\ n状态:\ t+状态+
\ n错误:\ t+误差);
}
});
返回JSON;
}
我一直在Google上搜寻这几天。如何赫克我访问返回的数据?任何帮助,将AP preciated。
解决方案要访问你需要的状态值:
数据[4] .STATUS
这是因为它是存储在第五元素数组中的一个对象,用状态
作为对象上的属性。
I'm creating an ajax app using jQuery 1.4.2 and I've tried using using get(), post() and the ajax() method itself. My php service returns:
[{"k":"label0","v":0.5},{"k":"label1","v":99.43},{"k":"label2","v":2.46},{"k":"label3","v":46.29},{"status":"OK"}]
in my success callback I have tried accessing as json.status and json[0][0] but it always returns "undefined". what am I doing wrong?
function getSysinfo(source) {
var json = null;
$.ajax({
url: source,
type: 'POST',
dataType: 'json',
success: function (data) {
json = eval("(" + data + ")");
$('#data').html(json.status);
alert(json[0][0]);
refreshChart(json);
},
error: function (request, status, error) {
alert("REQUEST:\t" + request + "\nSTATUS:\t" + status +
"\nERROR:\t" + error);
}
});
return json;
}
I've been googling this for days. How the heck do I access the returned data? any help would be appreciated.
解决方案To access that status value you would need:
data[4].status
This is because it is an object stored in the the fifth element in an array, with status
being a property on the object.
上一篇:消费使用JQuery AJAX WCF后/ REST服务AJAX、JQuery、REST、WCF
下一篇:创建JSON回报和QUOT;串"从web服务与jQuery的AJAX应用QUOT、JSON、web、AJAX