AJAX从文件中读取

Win*_*ker 1 ajax file-io

我正在使用AJAX从文本文件中读取.我如何只阅读第一行?

Dmi*_*mov 5

此代码应该可以帮助您从远程文本文件中读取:

var txtFile = new XMLHttpRequest();
txtFile.open("GET", "http://my.remote.url/myremotefile.txt", true);
txtFile.onreadystatechange = function() {
  if (txtFile.readyState === 4) {  // Makes sure the document is ready to parse.
    if (txtFile.status === 200) {  // Makes sure it's found the file.
      allText = txtFile.responseText; 
      lines = txtFile.responseText.split("\n"); // Will separate each line into an array
    }
  }
}
txtFile.send(null);
Run Code Online (Sandbox Code Playgroud)