繁体   English   中英

使用POST时变量未发送到服务器

[英]Variables not being sent to server when using POST

用户使用以下JavaScript / Ajax在其计算机上运行一个页面:

xmlhttp.open("POST", "ProcessRequest.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(encodeURIComponent("fname=Mr.&lname=tester"));

服务器端脚本ProcessRequest.php似乎无法访问变量。
例如, $_POST['fname']给出以下错误:

注意:未定义索引:fname

我究竟做错了什么? 我正在使用WAMP运行它。

您编码过多。 您需要的是这样的:

xmlhttp.send("fname=" + encodeURIComponent("Mr.") + "&lname=" + encodeURIComponent("tester"));

当然,您可以使用一个函数使它更干燥。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM