小编Shr*_*vas的帖子

使用 AJAX 发送文件数组

假设我有一个包含一些图像的数组:

var images = [image1, image2, image3]
Run Code Online (Sandbox Code Playgroud)

如何在单个请求中使用 AJAX 将这些图像发送到 php 文件?

以下代码不起作用:

$.ajax({
    url: 'PHP/posts.php',
    type: 'post',
    data: {data: images},
    success: function(data) {
      alert(data);
      location.reload();
    }
  });
Run Code Online (Sandbox Code Playgroud)

我的 HTML:

<div id="newPostFile">
    <label for="newPostFiles"><i class="fa fa-file-text-o" id="newPostFileIcon" aria-hidden="true"></i></label>
    <input type="file" name="newPostFiles" id="newPostFiles">
</div>
Run Code Online (Sandbox Code Playgroud)

Endgoal: Whenever a file is selected, the file is added to the array and when the submit button is clicked, all the files are uploaded at once.

javascript ajax jquery

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

ajax ×1

javascript ×1

jquery ×1