Home > front end >  AJAX read line by line TXT beg god for help
AJAX read line by line TXT beg god for help

Time:12-03

My demand is that ua. TXT storage is the user's useragent, I want to get the user of the current browser ua, and then compared with TXT it line by line, as if there is a contrast with the alert to find, if there is no comparison to the same alert didn't find out
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>




CodePudding user response:

Has been solved, but thank you bosses reply,
  •  Tags:  
  • Ajax
  • Related