检索到的json冗余数据

发布于 2024-11-05 19:28:22 字数 1182 浏览 0 评论 0原文

$('.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

女中豪杰 2024-11-12 19:28:22

不太确定这里返回的格式。通常框架 SQL 对象以其自己的对象格式返回数据集。您可能希望将 SQL 数据传递到数组对象中,然后将数组 json_encode 返回给客户端。

$returnData = array(
    'name' => $output[0]->name,
    'videopath' => $output[1]->videopath 
);

echo json_encode(array('success'=>1, 'data'=>$returnData));

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.

$returnData = array(
    'name' => $output[0]->name,
    'videopath' => $output[1]->videopath 
);

echo json_encode(array('success'=>1, 'data'=>$returnData));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文