关于jQuery通过Ajax使用post发送json数据的坑

1 $.ajax({
2    method:"POST",
3    dataType:"json",
4    contentType: "application/json",
5    data: JSON.stringify({"name":"litarussell"}),
6 })
7 .then(data=>{
8    console.log(data) 
9 })

由于设置了contentType为json格式,对于php来说,该数据就不会在$_POST数组中,在php7之后,只能通过file_get_contents('php://input')来获取该数据。

详见:http://php.net/manual/zh/reserved.variables.httprawpostdata.php

posted @ 2018-04-10 22:35  litarussell  阅读(266)  评论(0编辑  收藏  举报