我对此有点厌倦了。
我不知道为什么它一直告诉我文件未定义,因为它的声明和使用都在同一范围内。
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js"></script>
<script type="text/javascript">
var txtFile = new XMLHttpRequest();
var inputarea = document.inputtext;
txtFile.open("GET", "start.txt", true);
txtFile.onreadystatechange = function() {
// Makes sure the document is ready to parse.
if(txtFile.readyState === 4) {
// Makes sure it's found the file.
if(txtFile.status === 200) {
allText = txtFile.responseText;
// Will separate each line into an array
lines = txtFile.responseText.split("\n");
for(i = 0; i < lines.length; i++) {
var s = lines[i];
if(s.indexOf("nextpage") > -1) {
// Line is there
} else {
// Line is not there
inputarea.value += s;
}
}
}
}
}
txtfile.send();
</script>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<textarea name="inputtext" rows="4" cols="20" readonly="readonly">
</textarea>
<div>TODO write content</div>
</body>
</html>
编辑
问题已解决,但我现在收到另一个错误:
Uncaught TypeError: Cannot read property 'value' of undefined (00:27:29:739 | error, javascript)
at txtFile.onreadystatechange (public_html/index.html:29:42)