Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ajax发送变量,有时无法在php中检索到完美值_Php_Jquery_Ajax - Fatal编程技术网

ajax发送变量,有时无法在php中检索到完美值

ajax发送变量,有时无法在php中检索到完美值,php,jquery,ajax,Php,Jquery,Ajax,我已经将这个变量传递到php页面 type: 'POST', url: url', data: "id="+id+"&nowrole="+role+"&last="+last+"&title="+title+"&devlopdes="+devlopdes 有时,第一组值是 id=1234 role=staff last=45 title=check page developdes= view this http://hibihi.com/index.p

我已经将这个变量传递到php页面

 type: 'POST',
 url:   url',
 data: "id="+id+"&nowrole="+role+"&last="+last+"&title="+title+"&devlopdes="+devlopdes
有时,第一组值是

id=1234
role=staff
last=45
title=check page
developdes= view this
http://hibihi.com/index.php?act=view&id=1
http://hibihi.com/index.php?act=add&shipperid=1
id=1234
role=staff
last=45
title=check page
developdes= view this
http://hibihi.com/index.php?act=view
http://hibihi.com/index.php?act=add&shipperid=1
在php页面中

检索id=“1http://hibihi.com/index.php?act=add“未检索传递的“id”值

有时,第二组值是

id=1234
role=staff
last=45
title=check page
developdes= view this
http://hibihi.com/index.php?act=view&id=1
http://hibihi.com/index.php?act=add&shipperid=1
id=1234
role=staff
last=45
title=check page
developdes= view this
http://hibihi.com/index.php?act=view
http://hibihi.com/index.php?act=add&shipperid=1

检索正确的id=1234值。

如果您使用的是对象,只需在javascript中使用以下代码即可:

var obj = {};
obj[id]         = "1234";
obj[role]       = "staff";
obj[last]       = "45";
obj[title]      = "check page";
obj[developdes] = "view this";
obj[http1]      = "http://hibihi.com/index.php?act=view&id=1";
obj[http2]      = http://hibihi.com/index.php?act=add&shipperid=1";
然后

和你的PHP

$json = jsondecode($_POST[data]);
$id = $json->{'id'};

请在您的问题中发布变量
id
角色
。。。等等,当url格式错误时,所有变量都是如此!我确信变量中的值会导致url中断,Worn参数valuesCodeUriComponent()是您的friend@john史密斯:好的。。我会试试这个……如果您使用的是$\u POST,请尝试使用JSON.stringify。如果将所有变量放在一个对象中并使用JSON方法,那么将大数据发送到PHP脚本,然后在PHP中使用jsondecode访问每个变量是非常容易的。注意:不适用于IE8或更低版本。@john Smith:谢谢。。。encodeURIComponent()正在工作。检索正确的值。