xmlhttprequest无法查找文件但存在

时间:2014-07-11 03:25:09

标签: javascript asp.net xmlhttprequest

我只想问我是否正确执行代码:

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);
 }

每次触发时,它都会显示readystateno such file was found,但文件仍然存在。代码有问题吗?用我的URL?我做得对吗?我很抱歉,我是网络开发的新手。谢谢你的回复。

0 个答案:

没有答案