I'm trying to do a simple ajax call for a search, yet php is throwing error (notice):
Trying to get property of non-object in.. etc etc
This is the Angular http call:
console.log($scope.query); // this works fine and logs correctly
$http({
method: 'POST',
url: url,
//data: "searchTerm=" + $scope.query, // <-- also tried but failed
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}, {searchTerm: $scope.query})
also tried {"searchTerm": $scope.query}
PHP
$data = json_decode(file_get_contents("php://input"));
$searchTerm = $data->searchTerm;
Trying print_r($_POST);
in the PHP file gives an empty array Array()
Is there a better way to pass the data between the two?