XMLHttpRequest.open 的参数不足
Not enough arguments to XMLHttpRequest.open
我正在按照此处所述使用 AJAX2
监视 ajax 请求的进度,但我收到以下错误 "TypeError: Not enough arguments to XMLHttpRequest.open."
谁能帮忙解释为什么会出现这个错误?
我的密码是:
var oReq = new XMLHttpRequest();
oReq.addEventListener("progress", updateProgress);
oReq.addEventListener("load", transferComplete);
oReq.addEventListener("error", transferFailed);
oReq.addEventListener("abort", transferCanceled);
oReq.open();
// ...
// progress on transfers from the server to the client (downloads)
function updateProgress (oEvent) {
if (oEvent.lengthComputable) {
var percentComplete = oEvent.loaded / oEvent.total;
console.log(percentComplete+ " percent completed.");
// ...
} else {
console.log(" Unable to compute progress information since the total size is unknown.");
// Unable to compute progress information since the total size is unknown
}
}
function transferComplete(evt) {
console.log("The transfer is complete.");
}
function transferFailed(evt) {
console.log("An error occurred while transferring the file.");
}
function transferCanceled(evt) {
console.log("The transfer has been canceled by the user.");
}
此行出现实际错误
oReq.open();
该文档中的代码示例不完整,工作代码。它旨在向您展示如何向现有的工作 XMLHttpRequest 代码添加进度跟踪。
您需要自己填补空白(或者更好:构建一个基本的基于 XHR 的脚本,然后向其中添加进度跟踪)。这包括替换:
oReq.open();
真正调用 open
。参见 the documentation for open。您至少需要提供一个 HTTP 方法和一个 URL(均为字符串参数)。
open() 方法有三个参数
open('get' , url , true or false or null)
我正在按照此处所述使用 AJAX2
监视 ajax 请求的进度,但我收到以下错误 "TypeError: Not enough arguments to XMLHttpRequest.open."
谁能帮忙解释为什么会出现这个错误?
我的密码是:
var oReq = new XMLHttpRequest();
oReq.addEventListener("progress", updateProgress);
oReq.addEventListener("load", transferComplete);
oReq.addEventListener("error", transferFailed);
oReq.addEventListener("abort", transferCanceled);
oReq.open();
// ...
// progress on transfers from the server to the client (downloads)
function updateProgress (oEvent) {
if (oEvent.lengthComputable) {
var percentComplete = oEvent.loaded / oEvent.total;
console.log(percentComplete+ " percent completed.");
// ...
} else {
console.log(" Unable to compute progress information since the total size is unknown.");
// Unable to compute progress information since the total size is unknown
}
}
function transferComplete(evt) {
console.log("The transfer is complete.");
}
function transferFailed(evt) {
console.log("An error occurred while transferring the file.");
}
function transferCanceled(evt) {
console.log("The transfer has been canceled by the user.");
}
此行出现实际错误
oReq.open();
该文档中的代码示例不完整,工作代码。它旨在向您展示如何向现有的工作 XMLHttpRequest 代码添加进度跟踪。
您需要自己填补空白(或者更好:构建一个基本的基于 XHR 的脚本,然后向其中添加进度跟踪)。这包括替换:
oReq.open();
真正调用 open
。参见 the documentation for open。您至少需要提供一个 HTTP 方法和一个 URL(均为字符串参数)。
open() 方法有三个参数 open('get' , url , true or false or null)