真机调试时,请求异常,服务器返回false
发布于 6 年前 作者 yliu 14587 次浏览 来自 问答
onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    const that = this;
    if (options.tag) {
      that.setData({ bookTag: options.tag })
    }
    console.log(options)
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('acceptDataFromOpenerPage', function (res) {
      console.log("接收到数据", res)
      var temp=[]
      temp[1] = parseFloat(res.latitude)//纬度
      temp[0] = parseFloat(res.longitude)//经度
      that.data.location = temp.join(",")
      console.log("存储数据", that.data.location)
    })
    wx.request({
      url: 'https://routeplan.ml:3001/around',
      data: {
        location: this.data.location,
        type: 0,
        max_count: 100
      },
      method: "GET",
      success(res) {
        //返回结果内容在res.data中
        console.log(res.data)
        that.setData({
          result: res.data.result
        })
      }
    })

}

在开发者工具上进行服务器请求返回为true,且有返回数据

真机调试时无法请求到数据(开了不校验域名的)

查看服务器日志,请求为空

AppId: wx56c864f5e053f678

附:上个月都还可以,这个月就突然不行了

1 回复

你的这块的location,视图层需要不?不需要的话就不用放在data里面了,还有这块的异步请求和你获取经纬度时候的顺序有问题,把请求写在回调里面不行吗。

eventChannel.on('acceptDataFromOpenerPage', function (res) {
      console.log("接收到数据", res)
      var temp=[]
      temp[1] = parseFloat(res.latitude)//纬度
      temp[0] = parseFloat(res.longitude)//经度
      const location = temp.join(",")
       wx.request({
        url: 'https://routeplan.ml:3001/around',
        data: {
          location: location,
          type: 0,
          max_count: 100
        }
      })
回到顶部