使用PHP检索ajax datatype = json发布的数据 [英] Retrive data posted by ajax datatype=json with php
本文介绍了使用PHP检索ajax datatype = json发布的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将诸如页码之类的数据发送到php页面,以执行某些操作.然后,PHP代码向我发送了一个数组.为了在jQuery中获取php数组,我使用了json.它返回了一个数组,但是在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?
jQuery:
$.ajax({
type: 'POST',
url: 'php/pagging_employs_list.php',
data: 'id=testdata',
dataType: 'json',
cache: false,
success: function(result) {
alert(result[0]);
},
});
PHP:
$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
在这里不能使用,因为它仅适用于url编码的数据.
$_POST
cannot be used here because it only works with url encoded data.
例如,您需要阅读stdin的内容
You need to read from stdin, for example
$data = json_decode(file_get_contents('php://stdin'));
这篇关于使用PHP检索ajax datatype = json发布的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文