I now use ajax can read, but not read line by line comparison
& lt; The script type="text/javascript" & gt;
The function doAjaxCall (the_request) {
Var request=null;
If (window. The XMLHttpRequest) {
Request=new XMLHttpRequest ();
{} else if (window. ActiveXObject)
Request=new ActiveXObject (" Microsoft. XMLHTTP ");
}
If (request) {
Request. The open (" GET ", the_request, true);
Request. The onreadystatechange=function () {
If (request. ReadyState===4) {
If (request. Status==200 | | request. The status==0) {
The console. The log (request. The responseText);
}
}
}
Request. Send (null);
} else {
Alert (" error ");
}
}
</script>
CodePudding user response:
Try to write a demo resources front-end read TXT file
<meta charset="utf-8" & gt;
<body>
<script SRC="http://libs.baidu.com/jquery/2.0.0/jquery.min.js" & gt; </script>Var files=document. GetElementById (' files');
/*
I the content of the local document
"Early onset treasure" bai
The filled with clouds, qian du in jiangling also a day,
On both sides of the ape zhi, crow is endless, canoe already past thousands of mountains,
*/
Files. Onchange=function () {
Var file=files. The files [0];
Var reader=new FileReader ();
Reader. ReadAsText (file, "utf-8");//at the back of the parameter is to prevent the Chinese garbled
Reader. onl oad=function () {
Var STR=reader. Result;
Var 'arry=STR. The split (' \ r \ n')
'arry. ForEach ((item, index)=& gt; {
If (item. IndexOf (' bai ')!=1)
{
Alert (' in the first '+ (index + 1) +' line ')
}
});
The console. The log (' arry)
The console. The log (reader. The result);
}}
</script>