2011-10-23 64 views
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类型的值。但是,萤火虫抱怨数据未被定义。如果是这样的话,我该如何使用ajax中的响应数据?但是,萤火虫正在显示响应数据。我只需要知道如何使用从jquery访问响应的数据。

+0

您是否尝试过加入'的console.log(数据)'在你的成功函数中看看返回的是什么?我有点困惑,在你的问题中,你声明Firebug说数据没有被定义,但是它显示了响应数据。另外,是否有'data'对象在'reponse()'函数中被强制转换为数组的原因? – ima007

+0

我不知道cakePHP:'$ this-> Html-> url(array(“action”=>“retrieveVideoFeed”));'return? – Eric

+0

$ this-> Html-> url(array(“action”=>“retrieveVideoFeed”));它是基于cakephp – madi

回答

2

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); 
} 
+0

你是上帝,你明白我的情况:)) – madi

+1

@madi很高兴,帮助':)' – Rafay