xmlhttprequest请求

上传

 var xhr = new XMLHttpRequest();
    xhr.open('POST', 'http://posttestserver.com/post.php');
    xhr.onload = () => {
      if (xhr.status !== 200) {
        AlertIOS.alert(
          'Upload failed',
          'Expected HTTP 200 OK response, got ' + xhr.status
        );
        return;
      }

      // upload succeeded
      ...
    };
    var formdata = new FormData();
    formdata.append(photo, {type: "image/jpeg", name: ____, uri: ______ });

    if (xhr.upload) {
      xhr.upload.onprogress = (event) => {
        console.log('upload onprogress', event);
        if (event.lengthComputable) {
          this.setState({uploadProgress: event.loaded / event.total});
        }
      };
    }
    xhr.send(formdata);

  https://github.com/marcshilling/react-native-image-picker/issues/31

posted @ 2016-03-23 10:08  bodhicitta  阅读(204)  评论(0编辑  收藏  举报