I want to send a POST
request to a remote php file from an ionic app to save base64 encoded data in the database. When i pass POST
data, I can see that the post parameter is sent, but when i print the response from the php file, it is blank.
I tried this code:
controller.js
$http.post("someurl", {data: {"data333": 'peter'}});
When I print $_POST
or $_REQUEST
from php, it is a blank array, but from my console I can see that parameters are passed with the json {data: {"data333": 'peter'}}
.
I have allowed cross domain in both client and server.
I also tried the standard ajax way:
$http.defaults.headers.post["Content-Type"] = 'application/x-www-form-urlencoded; charset=UTF-8';
$http({
method : 'POST',
url : 'someurl/',
headers: {
'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
},
data : {"key": "value"}
})
Can anyone help me pass the data?
try this it should work, ensure you define $httpParamSerializerJQLike in the controller and youre good to go,
})})
User object to pass the data to the server. Hope it is helping to you
As posted in angularjs-http-post-does-not-send-data, this might be a problem between AngularJS using JSON and PHP expecting form data.
One answer is server-side / PHP:
The accepted answer tells you how to convert AngularJS data to a standard post request. It is lengthy. (JSON array to POST string etc)
The body needs to be uri encoded:
For more information, see AngularJS $httpParamSerializer Service API Reference
I ran into this problem a while ago . Including these headers in PHP api saved my day.
View details of my question here