我只想问我是否正确执行代码:
function Type2() {
var txtFile = new XMLHttpRequest();
txtFile.open("GET", "file://C:/Users/MyPC/Documents/My Reports/Hello.txt", true);
txtFile.onreadystatechange = function () {
alert('inside function');
if (txtFile.readyState === 4) { // Makes sure the document is ready to parse.
alert('readystate');
if (txtFile.status === 200) { // Makes sure it's found the file.
alert('file was found');
allText = txtFile.responseText;
alert(allText);
} else {alert('no file was found'); }
} else { alert('no readystate'); }
}
txtFile.send(null);
}
每次触发时,它都会显示readystate
和no such file was found
,但文件仍然存在。代码有问题吗?用我的URL?我做得对吗?我很抱歉,我是网络开发的新手。谢谢你的回复。