How can I upload files asynchronously
$(':button').on('click', function () {
$.ajax({
// Your server script to process the upload
url: 'upload.php',
type: 'POST',
// Form data
data: new FormData($('form')[0]),
// Tell jQuery not to process data or worry about content-type
// You *must* include these options!
cache: false,
contentType: false,
processData: false,
// Custom XMLHttpRequest
xhr: function () {
var myXhr = $.ajaxSettings.xhr();
if (myXhr.upload) {
// For handling the progress of the upload
myXhr.upload.addEventListener('progress', function (e) {
if (e.lengthComputable) {
$('progress').attr({
value: e.loaded,
max: e.total,
});
}
}, false);
}
return myXhr;
}
});
});
Also in JavaScript:
- javascript close window
- get promise result from json() javascript
- Javascript get text input value
- javascript get same elments from multiple arrays
- generate an array of random numbers javascript
- regular expression flags
- how to solve Could not write JSON: Infinite recursion (StackOverflowError)
- change favicon with javascript
- how to move an ellipse along the x axis in javascript
- json datetime
- loop in object javascript
- mdn select event
- ready function javascript
- memoization javascript
- pass params react js
- npm react native turn by turn navigation
- setinterval nodejs
- how to get value of button that click on it jquery
- set cookie javascript
- import json file javascript
- cli run js
- react template
- mongodb gte
- mlutiple css jquery