以下代码中的所有内容都将起作用,除了它永远不会触发 xhr.upload.onprogress 事件。
$(function(){
var xhr;
$("#submit").click(function(){
var formData = new FormData();
formData.append("myFile", document.getElementById("myFileField").files[0]);
xhr = new XMLHttpRequest();
xhr.open("POST", "./test.php", true);
xhr.send(formData);
xhr.onreadystatechange = function(){
if(xhr.readyState === 4 && xhr.status === 200){
console.log(xhr.responseText);
}
}
xhr.upload.onprogress = function(e) {
// it will never come inside here
}
});
});