我不能让下面的代码工作!
<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? 请有人帮忙。我会疯了!