首頁 >web前端 >js教程 >jQuery AJAX 可以透過 POST 方法處理檔案上傳嗎?

jQuery AJAX 可以透過 POST 方法處理檔案上傳嗎?

Linda Hamilton
Linda Hamilton原創
2024-12-25 04:25:09903瀏覽

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