开发者社区 问答 正文

支付宝小程序报无效参数

Uncaught (in promise) {error: 2, errorMessage: "无效参数"}

loadCity: function (longitude, latitude) {
    console.log(longitude, latitude)

    return new Promise(function (resolve, reject) {
      my.request({
        url: 'https://api.map.baidu.com/geocoder/v2/',
        method: "get",
        data: {
          ak: 'fZFXohYk16dGFbGEMow2Tz0vuxILoman',
          location: latitude + ',' + longitude,
          output: 'json'
        },
        success: function (res) {
          console.log(res)
          if (res.status == '200') {
            resolve({
              citycode: res.data.result.addressComponent.adcode
            });
          }
        },
        fail: function () {
          resolve("");
        }
      })
    }).catch((e) => {
      console.log('catch:', e);
    })
  }


app.loadCity(longitude, latitude).then(res => {})

展开
收起
dear-胡 2020-03-09 16:20:23 3578 分享
分享
版权
举报
1 条回答
写回答
取消 提交回答
  • 跨域问题

    我的是用浏览器…这种方式无效,虽然能加载出来文件但是还是会报 Uncaught (in promise) 的错, 然后开phpStudy 用loclahost的地址访问页面就不会报错

    或者使用 node 和 apache 开一个服务器运行

    2020-04-15 23:26:04 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
问答分类:
问答地址:
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等