我不能讓下面的代碼工作!
<input type="text" ng-model="name" >
<button ng-click="send(name);">SEND</button>
angular.module('myapp', []).
controller('MyController', ['$scope','$http', function ($scope,$http) {
$scope.name='Jim';
$scope.send=function() {
return $http({
method: 'POST',
data:{server:'Hi'},
url: 'test.php',
dataType: 'json'
}).then(function(data){console.log(data)},function(data){console.log('failure')});
};
}]);
和我的很簡單test.php
:
<?php
$request=$_POST['server'];
$request.='Jim';
echo json_encode($request);
?>
按下按鈕來發送,我收到($ HTTP成功返回):Object {data: ""Jim"", status: 200, config: Object, statusText: "OK"}
。爲什麼數據等於該對象以及爲什麼'Hi'未傳遞給PHP? 請有人幫忙。我會瘋了!