Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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
Php 在变量中保存ajax发送的查询字符串时出错_Php_Jquery_Ajax_Variables_Url - Fatal编程技术网

Php 在变量中保存ajax发送的查询字符串时出错

Php 在变量中保存ajax发送的查询字符串时出错,php,jquery,ajax,variables,url,Php,Jquery,Ajax,Variables,Url,我将向ajax页面发送一个变量值,如下所示 var d = $('#sTree2').sortableListsToString(); $.post('myscript.php?url='+d); d值为 item_a=0&item_b=0&item_b1=item_b&item_b2=item_b&item_b3=item_b&item_b4=item_b&item_b5= item_b&item_c=0&item_c1=ite

我将向ajax页面发送一个变量值,如下所示

var d = $('#sTree2').sortableListsToString();
$.post('myscript.php?url='+d);
d值为

item_a=0&item_b=0&item_b1=item_b&item_b2=item_b&item_b3=item_b&item_b4=item_b&item_b5=
item_b&item_c=0&item_c1=item_c&item_c2=item_c&item_c3=item_c&item_c4=item_c&item_c5=item_c&
item_d=0&item_d1=item_d&item_d2=item_d&item_d3=item_d&item_d4=item_d&item_d5=item_d&
item_e=0&item_f=0
在php文件中,我像往常一样保存该值

$url=$_REQUEST['url'];
echo $url;
但结果是

item_a=0
当我在控制台中打开network选项卡并查看ajax的预览时,我发现相同的错误值项_a=0,而标题是正确的,包含了我上面提到的整个URL

有什么建议吗


这是因为您没有正确编码字符串。您将获取两个单独的url编码字符串并将它们组合在一起。服务器有NO的想法,即您希望整个内容成为
url
值的一部分,因此它会做它应该做的事情-将内容解码为许多单独的key=value对

您需要对
d
进行URL编码,例如

item_a=0&item_b=0&etc.. -> item_a=&item_b=0&etc...

在php文件中使用
$\u POST['url']
,并通过如下方式发送数据:

$.post(url, data);

在没有查询字符串的情况下发送数据解决了这个问题

$.post('myscript.php?'+d);
然后在php文件中

$url=$_SERVER['REQUEST_URI'];
$url=end(explode("?",$url));
echo $url;

你期望项目a的值是什么?我期望url=item_a=0和item_b=0和item_b1=item_b和item_b2=item_b。。。etc并将整个url保存在php文件中的一个变量中,但发送的数据为item_a=0现在url为“u=项目a=0&;项目b=0&;项目b1=项目b&;项目b2=项目b&;项目b3=项目b&;项目b 4=项目b&;项目b 5=项目b&;项目c=0&;项目c1=项目c&;项目c 2=项目c&;项目c3=项目c&;项目c4=项目c&;项目c5=项目c&;项目d=0&;项目d1=项目d&;项目d2=项目d&;项目d3=项目d&;项目4=项目d&;项目5=项目d&;项目e=0&;项目_f=0“,结果仍然相同