Ajax content-type:application/json 请求 PHP 获取不到数据 如何获取?
Ajax 请求 参数 不能是对象 应用 json 字符串
data: JSON.stringify({'openid':'xiaoguan'})
----------------------
$.ajax({
url:"/auth/wxreg",
data:JSON.stringify({'openid':'xiaoguan'}),
async: false,
type:'post',
dataType:'json',
contentType:"application/json",
success: function(data) {
console.log('suc',data);
},
error:function(err) {
console.log('err',err);
}
});PHP 后台 需要使用 获取
$body = file_get_contents("php://input");
$req = json_decode($body);
var_dump($req->openid);
die();