收藏
回答

异步加载图片出现Failed to load image无法加载图片问题,请问怎么解决?相关帖无法解

图片链接复制到浏览器正常显示,直接卸载src标签里面也可以正常显示,求指教!

服务器自己的,没开防盗链!!!

报错提示

Failed to load image https://www.kjch.xyz/update2/images/wx90694dade63fe709.o6zAJs6GT7ALFlx70UXyHFtL_xuU.lkPgh3cgzSpG2f3d906f016e21895d4ade0976ff6d5c.png

the server responded with a status of 404 (HTTP/1.1 404) 

From server 120.79.54.134

完整代码

<!--index.wxml-->
<view class="container">
  <button bindtap='chooseImageTap'>上传图片</button>
  <view wx:if="{{xyz!=null}}">
      <!--<image src="{{(xyz)?xyz:'640.jpg;'}}"></image>-->
      <image src="{{xyz}}"></image>
      {{xyz}}
  </view>
 
</view>

JS代码

//index.js
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    imgs: [],//本地图片地址数组
    picPaths: [],//网络路径
    xyz: "null",
    abc: null
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
 
  },
  //添加上传图片
  chooseImageTap: function () {
    var that = this;
    wx.showActionSheet({
      itemList: ['从相册中选择', '拍照'],
      itemColor: "#00000",
      success: function (res) {
        if (!res.cancel) {
          if (res.tapIndex == 0) {
            that.chooseWxImage('album')
          } else if (res.tapIndex == 1) {
            that.chooseWxImage('camera')
          }
        }
      }
    })
  },
  // 图片本地路径
  chooseWxImage: function (type) {
    var that = this;
    var imgsPaths = that.data.imgs;
    wx.chooseImage({
      sizeType: ['original', 'compressed'],
      sourceType: [type],
      success: function (res) {
        console.log(res.tempFilePaths[0]);
        that.upImgs(res.tempFilePaths[0], 0) //调用上传方法
        console.log(res.tempFilePaths[0])
        that.abc(res.tempFilePaths[0])
      }
    })
  },
  //上传服务器
  upImgs: function (imgurl, index) {
    var that = this;
    wx.uploadFile({
      url: 'https://www.kjch.xyz/update2/uploadFile.do',//
      filePath: imgurl,
      name: 'file',
      header: {
        'content-type': 'multipart/form-data'
      },
      formData: null,
      success: function (res) {
        console.log("返回值:" + res) //接口返回网络路径
        var data = JSON.parse(res.data)
        that.data.picPaths.push(data['msg'])
        that.setData({
          picPaths: that.data.picPaths,
        })
        console.log(that.data.picPaths)
      }
    })
  },
  abc: function (e) {//该函数用于和后台交互
    var that = this;
    wx.request({
      url: 'https://www.kjch.xyz/update2/url', //仅为示例,并非真实的接口地址
      data: {
        URL: e,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log("abc返回值:" + res.data);
        that.setData({
          xyz: res.data
        })
      }
    })
    console.log(that.xyz)
  }
 
})


报错提示:



最后一次编辑于  2019-10-19
回答关注问题邀请回答
收藏

8 个回答

  • 谷谷
    谷谷
    2021-04-15

    解决了吗,同问

    2021-04-15
    有用 1
    回复
  • 睡前原谅一切
    睡前原谅一切
    2019-10-18

    大胆猜测,加了防盗链

    2019-10-18
    有用 1
    回复 3
    • 弈海
      弈海
      2019-10-18
      大佬,没有加啊
      2019-10-18
      回复
    • 何处不相逢
      何处不相逢
      2020-08-03
      嗯  果然去掉  防盗链  就好了
      2020-08-03
      回复
    • 睡前原谅一切
      睡前原谅一切
      2020-08-04回复何处不相逢
      0110 0110 0110
      2020-08-04
      回复
  • APP开发-末学门丰
    APP开发-末学门丰
    2023-06-06

    到底是为啥

    2023-06-06
    有用
    回复
  • Calvin
    Calvin
    2023-03-21

    异步加载的问题,解决了吗

    2023-03-21
    有用
    回复
  • 天魔&龙魂
    天魔&龙魂
    2019-10-22

    wx:if="{{xyz}}",和加载异步有关系吧

    2019-10-22
    有用
    回复 1
    • 弈海
      弈海
      2019-10-23
      是的,但是用过这个写法还是不能加载
      2019-10-23
      回复
  • 扶苏。
    扶苏。
    2019-10-21

    https://www.kjch.xyz  在小程序的业务域名配置了吗?


    2019-10-21
    有用
    回复 1
    • 弈海
      弈海
      2019-10-21
      配置了
      2019-10-21
      回复
  • 弈海
    弈海
    2019-10-18

    自己的tomcat服务器,没开防盗链

    2019-10-18
    有用
    回复
  • 思男
    思男
    2019-10-18

    这种一般都是网站资源防盗链设置的,如果是你的站点可以选择接触限制,不是的话想办法保存起来再用自己的url吧。

    2019-10-18
    有用
    回复 1
    • 弈海
      弈海
      2019-10-18
      大佬没有加
      2019-10-18
      回复
登录 后发表内容
问题标签