I cannot make the following code to work!
<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')});
};
}]);
and my very simple test.php:
<?php
$request=$_POST['server'];
$request.='Jim';
echo json_encode($request);
?>
By pressing button SEND, I am getting ($http returns successfully): Object {data: ""Jim"", status: 200, config: Object, statusText: "OK"}. Why data equals that object and why 'Hi' is not passed to PHP?
Please, someone to help. I am going to be crazy!