2014-04-22 15 views
2

不知道爲什麼我得到未定義的索引與我下面的代碼。我檢查了一切,但無法找到問題所在。在你的Ajax

$http({ 
    url: "php/mainLoad.php", 
    method: "GET", 
    data: {"userId":"1"} 
    }).success(function(data, status, headers, config) { 

     console.log(data); 
    }).error(function(data, status, headers, config) { 
     // $scope.status = status; 
     alert(status); 
    }); 

PHP

echo $_GET['userId']; 
+0

Emmm,奇怪的事情,什麼顯示var_dump($ _ REQUEST);一般來說? –

+0

你嘗試了'params:{userId:「1」}'?或者你確定url正在返回一個非未定義的數據? – Bellash

回答

2

parametere data期待的方法是POST,如果你需要通過$_GET得到它,使用params代替:

$http({ 
    url: "php/mainLoad.php", 
    method: "GET", 
    params: {"userId":"1"} // Change to `params` from `data`. 
}).success(function(data, status, headers, config) { 

    console.log(data); 
}).error(function(data, status, headers, config) { 
    // $scope.status = status; 
    alert(status); 
}); 
+0

omg thx for the magic bro! – user3522444