在jquery中访问php返回的json编码对象
我想通过ajax将一些数据发布到php函数中,然后获取php函数将返回的编码json对象,然后我想从该对象中获取信息(键和值),但我不知道如何获取,以下是我的代码:在jquery中访问php返回的json编码对象,php,jquery,ajax,json,Php,Jquery,Ajax,Json,我想通过ajax将一些数据发布到php函数中,然后获取php函数将返回的编码json对象,然后我想从该对象中获取信息(键和值),但我不知道如何获取,以下是我的代码: $.ajax({ url: "functions.php", dataType: "JSON", data: {id: id}, type: 'POST', success: function(json){ for(var i=0;i<json.length;i+
$.ajax({
url: "functions.php",
dataType: "JSON",
data: {id: id},
type: 'POST',
success: function(json){
for(var i=0;i<json.length;i++){
alert(json['fname']);
}
}
});
这样做相当简单:
var data = jQuery.parseJSON(json);
jQuery.each(data, function(i, item) {
jQuery('.derp').append(item.mname + "<br />");
});
var data=jQuery.parseJSON(json);
每个(数据、函数(i、项){
jQuery('.derp').append(item.mname+“
”);
});
参考
$.ajax({
url: "functions.php",
dataType: "JSON",
data: {id: id},
type: 'POST',
success: function(json){
for(var i=0;i<json.length;i++){
alert(json[i].fname);
}
}
});
$.ajax({
url:“functions.php”,
数据类型:“JSON”,
数据:{id:id},
键入:“POST”,
成功:函数(json){
对于(var i=0;i和/或.alert(json[i]['fname']);
$.ajax({
url: "functions.php",
dataType: "JSON",
data: {id: id},
type: 'POST',
success: function(json){
for(var i=0;i<json.length;i++){
alert(json[i].fname);
}
}
});