In an attempt to transfer a file using XMLHttpRequest, you might encounter the following error:
The request was rejected because no multipart boundary was found.
This error signifies that your code lacks the correct approach to handling multipart form data. To rectify this issue, let's address two key areas:
var formData = new FormData(); formData.append("thefile", file); xhr.send(formData);
By utilizing FormData, the file becomes accessible through the PHP variable $_FILES['thefile'].
Remember to consult documentation and demos from MDC and Mozilla Hack for further guidance on this topic.
Previous Incorrect Suggestion:
The earlier answer incorrectly stated that xhr.send(file); transmits the raw post data. While it does send the file, it's imperative to employ FormData to ensure proper parsing on the server. Therefore, the above correction is crucial for achieving the desired functionality.
以上是如何解決使用Ajax XMLHttpRequest上傳檔案時出現的多部分邊界錯誤?的詳細內容。更多資訊請關注PHP中文網其他相關文章!