11-4 上传视频后,跑完进度条100% 提示 请求失败

来源:

maBi99

2016-11-30

老师你好,卡在11-4有半个月了 各种问题

http://szimg.mukewang.com/583e91e70001a6ac21281348.jpg

写回答

2回答

Scott

2016-11-30

这是请求哪个请求 url 失败了?把请求失败的错误 err 打印出来看看

0
5
maBi99
非常感谢!
2016-12-01
共5条回复

maBi99

提问者

2016-11-30

_upload(body){
    var that = this
    var xhr = new XMLHttpRequest()
    var url = config.qiniu.upload

    console.log(body)

    this.setState({
      videoUploading: true,
      videoUploaded: false,
      videoUploadedProgress: 0
    })
    xhr.open('POST',url)
    xhr.onload = () => {
      if (xhr.status !== 200) {
        //AlertIOS.alert('请求失败')
        console.log(xhr.responseText)

        return
      }
      if (!xhr.responseText){
        AlertIOS.alert('请求失败2')
        return
      }
      var response

      try{
        response = JSON.parse(xhr.response)
      }
      catch (e) {
        console.log(e)
        console.log('parse fails')
      }

      console.log(response)
      if (response){
        that.setState({
          video: response,
          videoUploading: false,
          videoUploaded: true
        })
      }
    }
    if (xhr.upload){
      xhr.upload.onprogress = (event) => {
        if (event.lengthComputable){
          var percent = Number((event.loaded / event.total).toFixed(2))
          that.setState({
            videoUploadedProgress: percent
          })
        }
      }
    }
    xhr.send(body)
  },

注释的地方

0
0

贯穿全栈React Native开发App

全面掌握React Native技术,不止步前端开发,让你移动领域大放光彩

946 学习 · 385 问题

查看课程