XMLHttpRequest由js向PHP传递数据,用的POST方法。
数据成功传过去了,用file_get_contents('php://input', 'r');可以获取到xmlhttp传过来的数据.
但我用$name = $_POST['username'];获取并打印$name时告诉我没有找到username,$_POST接受也是空的。
js这边这么写的:
var username = "abc";
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send("username=" + username);
查了一下,说如果php://input能够接收到内容,说明header写的有问题,不知道问题在哪,望大神指教。
php页面有这句话:header('Content-Type: text/html; charset=utf-8');
浏览器用的不是IE