weixin_33697898 2015-06-07 02:21 采纳率: 0%
浏览 13

Ajax发布图像

So the function below works exactly as I want it to except it only sends one of the initial files (the argument is an array of files). When I try to adjust the current function it affects the script in ways that I don't really understand...

Honestly I might just iterate through the array and then ignore the rest of the script, but I wanted to post to see if anyone else could explain what's going on because it irritates me that I can't figure it out...

Any help would be appreciated!!

    function readfiles(files) {
       // debugger;
        var formData = tests.formdata ? new FormData() : null;
        for (var i = 0; i < files.length; i++) {
          if (tests.formdata) formData.append('file ', files[i]);
          previewfile(files[i]);
        }

        // now post a new XHR request
        if (tests.formdata) {
          var xhr = new XMLHttpRequest();
          xhr.open('POST', './file_upload_parser.php');
          xhr.onload = function() {
            progress.value = progress.innerHTML = 100;
          };

          if (tests.progress) {
            xhr.upload.onprogress = function (event) {
              if (event.lengthComputable) {
                var complete = (event.loaded / event.total * 100 | 0);
                progress.value = progress.innerHTML = complete;
              }
            }
          }

          xhr.send(formData);
        }
    }
  • 写回答

1条回答 默认 最新

  • lrony* 2015-06-07 02:30
    关注

    Try

    formData.append('file[]', files[i]);
    

    the [] represents arrays in php for request data.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度