我遇到麻煩使用PHP和角度進行POST或使用POST發送數據。我將問題簡化爲最簡單的情況,但仍然是一個空陣列。如何從角度ajax使用php獲取POST數據
這裏是我的角碼
this.search = function(){
console.log("searching");
$http({
method: 'POST',
url: 'search/',
data: {search:1, direct: true}
}).then(function successCallback(response) {
console.log(response.data);
}, function errorCallback(response) {
console.log("Error retreaving data.");
console.log(response);
});
}
和我的PHP代碼:
<?php
header('Content-type: application/json');
echo json_encode($_POST) ;
?>
有趣的是,在這兩個地方使用GET,它的工作原理:/
最有可能與http://stackoverflow.com/questions/19254029/angularjs-http-post-does-not-send-data – JCOC611