检索到的json冗余数据
$('.editBtn').click(function(){//EDIT BUTTON EVENT
$.getJSON('edit.php?url='+encodeURI($(this).siblings('a').attr('id'))+'&action=edit',function(data){
$.each(data, function(key, val) {
alert(key+': '+val);
});
});
});//EDIT BUTTON END
这是有问题的 php 部分:
elseif($_GET['action']=='edit'){
$output=$mysql->getDb()->query("select * from video
where url='{$_GET['url']}'")->fetchAll();
header("content-type: application/json");
echo json_encode($output[0]);
}
发生的情况是,单击 .editBtn
按钮后,警报会弹出 0:value0, 1:value1,...
然后再次出现,但是在某种程度上,我只希望它是 name0:value0, name1:value1,...
发生了什么?
ps php 独立运行:
{"url":"www.vimeo.com\/20721308","0":"www.vimeo.com\/20721308","title":"Dis-patch Festival RIP" ,"1":"Dis-patch Festival RIP","description":"遗憾的是,在此致敬中,我们对 Dis-patch Festival 贝尔格莱德版进行了最后的告别“RIP”视频拼贴。结束永远是开始......","2":"遗憾的是,在这个致敬“RIP”视频拼贴的结尾中,我们向贝尔格莱德 Dis-patch 音乐节告别。永远是开始...","country":"塞尔维亚","3":"塞尔维亚","postDate":"2011-05-07 05:56:04","4":"2011-05-07 05:56:04","视图":null,"5":null}
$('.editBtn').click(function(){//EDIT BUTTON EVENT
$.getJSON('edit.php?url='+encodeURI($(this).siblings('a').attr('id'))+'&action=edit',function(data){
$.each(data, function(key, val) {
alert(key+': '+val);
});
});
});//EDIT BUTTON END
and here is php part in question:
elseif($_GET['action']=='edit'){
$output=$mysql->getDb()->query("select * from video
where url='{$_GET['url']}'")->fetchAll();
header("content-type: application/json");
echo json_encode($output[0]);
}
what happens is that upon clicking .editBtn
button alert pops up 0:value0, 1:value1,...
and then goes again but in a way that i only want it to be name0:value0, name1:value1,...
what is going on?
p.s. php run independently:
{"url":"www.vimeo.com\/20721308","0":"www.vimeo.com\/20721308","title":"Dis-patch Festival R.I.P.","1":"Dis-patch Festival R.I.P.","description":"Sadly, the last goodbyes to the Dis-patch Festival Belgrade edition in this tribute \"R.I.P.\" video collage. The end is always the beginning...","2":"Sadly, the last goodbyes to the Dis-patch Festival Belgrade edition in this tribute \"R.I.P.\" video collage. The end is always the beginning...","country":"serbia","3":"serbia","postDate":"2011-05-07 05:56:04","4":"2011-05-07 05:56:04","views":null,"5":null}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不太确定这里返回的格式。通常框架 SQL 对象以其自己的对象格式返回数据集。您可能希望将 SQL 数据传递到数组对象中,然后将数组 json_encode 返回给客户端。
Not exactly sure of the format being returned here.. Usually framework SQL objects return the data set in it's own object format.. You probably want to pass the SQL data into an array object, and then json_encode the array back to your client.