I have this html / javascript :
<html>
<head>
</head>
<body>
<script src="view/backoffice/assets/plugins/jquery/jquery-1.11.1.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
var data = {'user_id':'2680',
'ship_to_name':'John Doe',
'ship_to_address':'Somewhere in Jawa Timur',
'ship_to_city':'Surabaya',
'ship_to_area':'Wonocolo',
'ship_to_phone':'080000000'};
$.ajax({
url: "../controller/ctrl.php",
type: 'POST',
contentType:'application/json',
data: JSON.stringify(data),
dataType:'json'
});
});
</script>
</body>
</html>
and I have this PHP on my server :
<?php
$jsonReceiveData = json_encode($_POST);
file_put_contents('storedvar.php', $jsonReceiveData);
?>
but what I got in storedvar.php
is just empty variable of json. just like this []
.
why I can't get json sent data? thank you.