php通过ajax post方法收到编码字符串时生成一个空字符串?

时间:2013-11-04 10:53:35

标签: php

虽然在论坛中听到PHP自动转换通过AJAX GET或POST方法发送的编码字符串。我使用ajax post方法发送数据,该方法使用encodeURIComponent()函数进行编码。我的代码段是:

var name = document.getElementById("name").value;
   var url = "decode.php";
   var param = "name=" + name;

   ajaxRequest.open("POST", url, true);

//Send the proper header information along with the request
ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", param.length);
ajaxRequest.setRequestHeader("Connection", "close");

    ajaxRequest.send(encodeURIComponent(param)); 

当服务器收到它时,如果我尝试回复它(结果通过ajax响应显示),它只显示空字符串:

<?php
 $content = $_POST['name'];
 echo $content;
?>

如何让PHP返回正确的输入字符串?我很困惑!

0 个答案:

没有答案