2014-05-22 66 views
0

我試圖使用httpGET檢索我的數據。如何在我的情況下通過http請求檢索數據

在我js代碼

$http({ 
     url: "test.com/api/?title=1", 
     method: "GET", 
    }).success(function(data) { 
     $scope.title = data; //I have data 
     var name = $scope.title[0].name; 

     $http({ 
      url: name + "?name=name", 
      method: "GET", 
     }).success(function(name) { 
      console.log(name) //no response at all. 
     }) 
     $scope.initTree(); 

    }).error(function(data) { 

    }); 

所以基本上我有1個http requrest包裹在另一個http請求。我似乎無法獲得第二個請求數據。任何人都可以幫助我嗎?謝謝!

+1

我敢打賭,嵌套'$ http'請求失敗。檢查開發工具中的網絡選項卡,並確保從該請求返回有效的響應。 –

回答

1

@Marc Kline說,可以happend唯一的問題是,你的第二個$http失敗,你可以添加.error回調,就像你在第一完成並在控制檯中記錄錯誤:

$http({ 
    url: name + "?name=name", 
    method: "GET", 
}).success(function(name) { 
    console.log(name) //no response at all. 
}).error(function(err) { 
    console.log(err); 
}); 
相關問題