I'm sending data to the server as follow:
$scope.saveCaption = function(user_id) {
var target = document.getElementById('toRender');
html2canvas(target, {
onrendered: function(canvas) {
$http({
url: "/production/save.php?user_id="+user_id,
method: "POST",
headers: {
'Content-type': 'application/x-www-form-urlencoded'
},
data: {
//image: canvas.toDataURL("image/png"), // commented out for testing only
news: 'test'
}
}).success(function(data, status, headers, config) {
console.log('success');
$scope.data = data;
}).error(function(data, status, headers, config) {
console.log('failed');
$scope.status = status;
});
}});
}
And trying to read it with PHP - save.php
:
$data = $_POST['news'];
echo "data is $data"; die;
The problem is that $_POST['news']
is always blank?
This is the data sent:
{"news":"test"}
Notice it's JSON, yet I specifically tried to change the content type:
'Content-type': 'application/x-www-form-urlencoded'
So how can I send normal data as opposed to JSON? Or, how can I get the php to read the JSON properly, I tried $data = json_decode($_POST['news'])
but that gives blank too