简体   繁体   中英

How to handle json data, which I send via ajax request, in php script?

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?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM