如何访问控制器返回的结果

发布于 2024-12-11 13:32:36 字数 596 浏览 0 评论 0原文

我在我的项目中使用 cakePHP,并且有以下 Jquery 脚本

$.ajax({
                url: '<?php echo $this->Html->url(array("action" => "retrieveVideoFeed"));?>',
                dataType: "json",
                data: {
                    vid: $v_id
                },
                success: function( data) {
                                            response([data]);
                }
            });

现在我想使用来自控制器的响应数据,当我这样做时:

data.example,它应该给出控制器响应的 json 类型的值。然而,firebug 抱怨数据没有定义。如果是这样的话,我该如何在ajax中使用响应数据?然而,萤火虫正在显示响应数据。我只需要知道如何使用 jquery 访问响应的数据。

I am using cakePHP for my project and i have the following Jquery script

$.ajax({
                url: '<?php echo $this->Html->url(array("action" => "retrieveVideoFeed"));?>',
                dataType: "json",
                data: {
                    vid: $v_id
                },
                success: function( data) {
                                            response([data]);
                }
            });

Now i want to use the response data from the controller and when i do :

data.example, it should give the value of the json type that is responded by the controller. However, firebug is complaining that data is not defined. If that is the case, how can i use the response data in the ajax? However the firebug is showing the response data. I just need to know how can i use access the responded data from jquery.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

居里长安 2024-12-18 13:32:36

thsi 是您在评论中发布时获得的 json

{
    "apiVersion": "2.1",
    "data": {
        "id": "Ahg6qcgoay4",
        "uploaded": "2008-03-10T17:30:17.000Z",
        "updated": "2011-10-23T04:17:10.000Z",
        "uploader": "dothetest",
        "category": "Howto",
        "title": "Test Your Awareness: Do The Test",
        "description": "How many passes does the team in white make? Test your awareness and Do the Test!"
    }
}

在成功处理程序中访问它,例如

success:function(data){
alert(data.data.id);
//or
console.log(data.data.id);
}

thsi is the json you are getting as you have posted in the comments

{
    "apiVersion": "2.1",
    "data": {
        "id": "Ahg6qcgoay4",
        "uploaded": "2008-03-10T17:30:17.000Z",
        "updated": "2011-10-23T04:17:10.000Z",
        "uploader": "dothetest",
        "category": "Howto",
        "title": "Test Your Awareness: Do The Test",
        "description": "How many passes does the team in white make? Test your awareness and Do the Test!"
    }
}

access it in the success handler like

success:function(data){
alert(data.data.id);
//or
console.log(data.data.id);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文