2011-10-23 133 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