0

在我的表单中,我添加了输入文件。

<input name="uploadedFile" type="file" size="50" accept="application/pdf" />

我有这个ajax:

$("#submit").click(function() {
  $.ajax({
    type: "POST",
    url: "submit.php",
    data: $("form").serialize(),
    success: function(result){
       alert(result);
    });
    return false;
});

如何将文件数据传递给 submit.php 并使用 submit.php 中的代码上传。谢谢。

4

1 回答 1

7

jQuery serialize doesn't support file type inputs. From the docs:

Data from file select elements is not serialized.

You will need to roll your own solution using the HTML5 FileReader API, to read the contents of the input as a base64-encoded string.

More likely, you will want to use traditional HTML form submission and avoid AJAX altogether for this.

于 2013-02-19T20:49:45.753 回答