I have a simple POST http request and is getting an error Undefined property: stdClass::$number
and Undefined property: stdClass::$message
. Here are my codes:
smsController.js
angular
.module('smsApp')
.controller('smsController', smsController)
.config(config);
function config($routeProvider) {
$routeProvider
.when('/', {
controller: 'smsController',
templateUrl: 'app/views/messageForm.html'
});
}
function smsController($scope, $http) {
$scope.sendMessage = function() {
$scope.loading = true;
$scope.smsForm = {
number: undefined,
message: undefined
};
var data = {
number: $scope.smsForm.number,
message: $scope.smsForm.message
};
var req = {
method: 'POST',
url: 'app/endpoints/sendsms.php',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: data
};
$http(req)
.then(function successCallback(response) {
console.log(response);
$scope.loading = false;
}, function errorCallback(response) {
console.log(response);
});
}
}
messageForm.html
<div ng-hide="loading">
<div class="input-field col s12">
<input type="text" ng-model="smsForm.number" maxlength="11">
</div>
<div class="input-field col s12">
<textarea ng-model="smsForm.message" maxlength="200"></textarea>
<button ng-click="sendMessage()">Send</button>
</div>
</div>
sendsms.php
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
echo json_encode($request);
There is no data being passed and I'm getting the undefined property error. Am I missing something here?