Reputation: 7269
I am sending some json data with ajax:
function send() {
$.ajax({
url: '/index.php?action=setShopOrdersGoods&order_id='+orderId,
type: 'post',
dataType: 'json',
success: function (data) {
$('#target').html(data.msg);
},
data: JSON.stringify(goods)
});
}
There are no problems with it. Firebug console screen:
Soajax request is sending okay. Now I need to handle it.
How I can do this?
echo __FILE__;
echo '<pre>';
var_dump($_POST);
echo '</pre>';
exit;
This code shows nothing. Looks like there are no data send via post. Firebug response tab of sent ajax request:
How I can handle json data in php file then?
Upvotes: 1
Views: 243
Reputation: 912
Json data does not receive in post.
$json = file_get_contents('php://input');
$post = json_decode($json, TRUE);
echo __FILE__;
echo '<pre>';
var_dump($post);
echo '</pre>';
exit;
Upvotes: 3