首页 >web前端 >js教程 >jQuery AJAX 可以通过 POST 方法处理文件上传吗?

jQuery AJAX 可以通过 POST 方法处理文件上传吗?

Linda Hamilton
Linda Hamilton原创
2024-12-25 04:25:09899浏览

Can jQuery AJAX Handle File Uploads via the POST Method?

jQuery Ajax 文件上传 - 我可以使用 POST 方法吗?

问题:

是否可以使用以下方法使用 AJAX 请求的 POST 方法执行文件上传的 jQuery 代码?

    type: "POST",
    timeout: 50000,
    url: url,
    data: dataString,
    success: function (data) {
        alert('success');
        return false;
    }
});```

**Answer:**

Previously, file upload was **not** possible through AJAX. However, with the introduction of XHR2, file upload through AJAX is supported using the FormData object.

**Clarifications:**

* Data part must be filled with an instance of FormData to include file data.
* For older browsers without XHR2 support, file upload through AJAX is still not possible.

**Support:**

Starting from the following desktop browser versions, FormData is supported:

* IE 10+
* Firefox 4.0+
* Chrome 7+
* Safari 5+
* Opera 12+

以上是jQuery AJAX 可以通过 POST 方法处理文件上传吗?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn