2016-03-01 94 views
1

我想從一個PHP腳本獲取數據到我的角度應用程序。我正在使用此代碼來獲取數據。然而,它失敗了,然後給我沒有信息爲什麼。AngularJS http php echo

var req = { 
     method: 'GET', 
     url: 'http://www.hott-source.com/hangman/getMemory.php', 
     data: { } 
    } 

    $http(req).then(function(response){ 
     alert("WINNER"); 
     $scope.knownWords = response.data; 
    }, function(response){ 
     alert(response.data); 
    }); 

的PHP腳本返回

[ 
    ["A","I"], 
    ["BE","BY","DO","GO","IN","ME","MY"], 
    ["CAT","COW","DOG","GOD","HIT","MAT","PAT","PIG","RUN","YOU"], 
    ["BAND","BIRD","CART","CHIP","DOVE","JUMP","LOVE","READ"], 
    ["CHIRP","HAPPY","HORSE"], 
    ["CHURCH","HANSON","HITTER","PEOPLE","PRIEST","STRIKE","THOMAS"], 
    ["BELINDA","BUILDER","SHOOTER"], 
    ["CLAPPING","ELEPHANT"], 
    ["COLLECTION"] 
] 

我已經驗證爲JSON。在PHP文件我設置頁眉內容類型爲JSON之前我把它

header('Content-Type: application/json'); 
echo json_encode($newArray); 

response.data警報爲空

我如何從PHP腳本中的數據到我的$範圍。 knownWords

+1

您是否通過'http:// www.hott-source.com /'或您位於另一個域的js發出請求? –

+0

嘗試用'console.log'而不是'alert'並檢查開發人員工具中的日誌。 – cezar

+0

@BobSponge該應用程序正在我的電腦上運行。服務器是我在別處租用的服務器。 –

回答