sasan mohammadi sasan mohammadi - 4 months ago 35
jQuery Question

Retrive data posted by ajax datatype=json with php

I send a data like page number to a php page to do some things. Then php code sends me an array. To get php array in jQuery I used json. It has returned an array but in php page it can't get the page number that I send?


type: 'POST',
url: 'php/pagging_employs_list.php',
data: 'id=testdata',
dataType: 'json',
cache: false,
success: function(result) {


$params = json_decode($_POST['id']);
// here that i want to use data, not working an i vant get id value

$array = array(1,2,3,4,5,6);
echo json_encode($array);


$_POST cannot be used here because it only works with url encoded data.

You need to read from stdin, for example

$data = json_decode(file_get_contents('php://stdin'));