Home >Web Front-end >JS Tutorial >How to Perform jQuery Ajax File Uploads Without Plugins?
File upload using jQuery's AJAX requires the use of XHR2, supported by modern browsers. If you want to perform file upload using AJAX without a plugin, you need to use theFormDataobject.
Code:
var formData = new FormData(); formData.append("file", file); // Replace "file" with your file input element's name $.ajax({ type: "POST", timeout: 50000, url: url, data: formData, contentType: false, processData: false, // Don't process the form data, leave it as pure binary data success: function (data) { alert('success'); return false; } });
Notes:
The above is the detailed content of How to Perform jQuery Ajax File Uploads Without Plugins?. For more information, please follow other related articles on the PHP Chinese website!