如何在 XMLHttpRequest 中显示进度
How to show Progress in XMLHttpRequest
我使用XMLHttpRequest
上传文件,我想在提交文件前显示一个LoadingView,但是LoadingView没有出现,也不起作用。
我使用 Asp.net MVC 进行编码。
在JavaScript中:
// For display Loading View
function updateProgress(oEvent) {
if (oEvent.lengthComputable) {
//Loading
} else {
}
}
$('body')
.on('click', '#bUpload', function() {
var xmlHttpRequest = new XMLHttpRequest();
if (!window.XMLHttpRequest) {
xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttpRequest.addEventListener("progress", updateProgress);
xmlHttpRequest.open("POST", '@Url.Action("****", "****", new {area = "****"})', true);
xmlHttpRequest.send();
});
您可以将事件侦听器添加到您的 xmlHttpRequest。
MDN 对此有很好的文档。
我使用XMLHttpRequest
上传文件,我想在提交文件前显示一个LoadingView,但是LoadingView没有出现,也不起作用。
我使用 Asp.net MVC 进行编码。
在JavaScript中:
// For display Loading View
function updateProgress(oEvent) {
if (oEvent.lengthComputable) {
//Loading
} else {
}
}
$('body')
.on('click', '#bUpload', function() {
var xmlHttpRequest = new XMLHttpRequest();
if (!window.XMLHttpRequest) {
xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttpRequest.addEventListener("progress", updateProgress);
xmlHttpRequest.open("POST", '@Url.Action("****", "****", new {area = "****"})', true);
xmlHttpRequest.send();
});
您可以将事件侦听器添加到您的 xmlHttpRequest。
MDN 对此有很好的文档。