Home > Web Front-end > JS Tutorial > Can jQuery AJAX Handle File Uploads via the POST Method?

Can jQuery AJAX Handle File Uploads via the POST Method?

Linda Hamilton
Release: 2024-12-25 04:25:09
Original
903 people have browsed it

Can jQuery AJAX Handle File Uploads via the POST Method?

jQuery Ajax File Upload - Can I Use POST Method?

Question:

Is it possible to use the following jQuery code to perform file upload using the POST method of an AJAX request?

    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+
Copy after login

The above is the detailed content of Can jQuery AJAX Handle File Uploads via the POST Method?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template