1

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:

enter image description here

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:

enter image description here

How I can handle json data in php file then?

12
  • how do you evaluate that your php shows nothing? If you just open the path to it it surely will show nothing since it needs a post request for that. Are you aware of that? You browser tools can show you the servers response for whem you send data via ajax. Try that. Commented Jun 18, 2014 at 11:27
  • @DS9 If dumping $_POST shows nothing, it is very unlikely that $_POST['items'] will show something right? Commented Jun 18, 2014 at 11:28
  • I updated my question - added response - result of php code above. Commented Jun 18, 2014 at 11:28
  • @Sharikov. Is your PHP code in index.php? Maybe at the top? Commented Jun 18, 2014 at 11:29
  • your response tab shows ajax.php but you use index.php in your json. this doesn't seem right Commented Jun 18, 2014 at 11:30

1 Answer 1

3

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;
Sign up to request clarification or add additional context in comments.

5 Comments

Worked. What is php://input?
json data is saved into tmp, which is get through it
Wow. I did not know that. How did i not know that? Frameworks! They take all the work out of your hands and leave you clueless :-D
@AndreschSerj I am not using framework. Simple logic. The question was not about how I handle ajax request etc. I asked why I am getting nothing when var_dump($_POST) and author of this answer helped me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.