【问题标题】:Variables not being sent to server when using POST使用 POST 时未将变量发送到服务器
【发布时间】:2013-03-10 06:37:22
【问题描述】:

用户在其计算机上使用以下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 运行它。

【问题讨论】:

    标签: php javascript ajax wamp


    【解决方案1】:

    你编码太多了。你需要的是这样的:

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

    当然你可以使用一个函数来让它更干。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-05
      • 2022-01-23
      • 1970-01-01
      • 2014-01-04
      • 1970-01-01
      • 2018-05-07
      • 2012-05-16
      相关资源
      最近更新 更多