WX.Request 里的Data传不到PHP中去
发布于 5 年前 作者 panyang 16858 次浏览 来自 问答

服务器上的代码如下:

 Welcome <?php echo $_POST[“fname”]; ?>!<br>

 You are <?php echo $_POST[“age”]; ?> years old. 

小程序的代码如下:

 wx.request({

     url: ‘https://*******/****/test.php’,

     data: { fname:‘nail’, age:‘33’},

     method: ‘POST’, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT

      header: {“Content-Type”:“application/json”}, // 设置请求的 header

     success: function(res){

          console.log(res)

     },

结果返回:

  1. data:" Welcome !<br> ↵ You are  years old. "

  2. errMsg:"request:ok"

传过出的参数,没有抓出来。

3 回复

content-type’:‘application/x-www-form-urlencoded

2楼正解,已经搞定,谢谢

可能是你的 php 不支持全小写的 Content-Type,我觉得这是开发者工具的 bug, 全转成小写是不规范的。

回到顶部