I have a small php server that i developed. The server waits to serve json files that will be sent to him.
I created an html page and i am using jquery to try send a json file to my server.
I have a button and when i press it :
$("button").click(function(){
var data = '{"deviceUUID":"25f998", "os":"bb", "pushToken":"l1355436gdfsfaddsl"}';
alert("User: " + userId + "\n" + "Data: " + data);
$.ajax({
type: "POST",
url: "http://192.148.2.123/Server_CityInfo/register.php",
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json"
});
});
However the json file that arrives in the server is empty.. I know the server works , cause i have done post requests to it through java , obj-c , c# ...
What could be the problem here? The data variable on alert prints : {"deviceUUID":"25f998", "os":"bb", "pushToken":"l1355436gdfsfaddsl"}
which is in the right json format , that my server accepts.
THIS IS MY SEVER SIDE , PHP
// We use php://input to get the raw $_POST results.
$json = file_get_contents('php://input');
$json_post = json_decode($json, true);
//creating variables from received json
$deviceUDID = $json_post['deviceUUID'];
$os = $json_post['os'];
$pushToken = $json_post['pushToken'];
So when i try to print the deviceUUID
, or os
or pushToken
they are empty. In my database , that they are automatically inserted they appear as NULL
. That means that the post request arrives , but empty... or in wrong format..