今天遇到一个开发者提供过来的bug,描述大概就是没有获取到xmlhttp.send()中的数据!
代码大概就是下边这样:
xmlhttp.open("POST", "http://www.baidu.com?company="+company+"&position="+position+"&phone="+phone, true);
xmlhttp.send("name=123&pxx=666");
但是php后台却获取不到xmlhttp.send
中的参数。
具体的解决方法如下:
1、使用file_get_contents('php://input')
;可以获取到xmlhttp.send()
中的内容
2、或者在xmlhttp.open()
之后添加代码
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
php
中的代码$_POST
就可以获取到xmlhttp.send()
的内容了