admin管理员组文章数量:1405288
On www.example/page_a/ is it possible to run a javascript code that searches for the text "hello" inside the file located at www.example/page_b/my_file.txt ?
Is this possible with javascript/jquery/ any other javascript framework?
On www.example./page_a/ is it possible to run a javascript code that searches for the text "hello" inside the file located at www.example./page_b/my_file.txt ?
Is this possible with javascript/jquery/ any other javascript framework?
Share Improve this question edited Oct 12, 2016 at 10:46 shubham715 3,3021 gold badge19 silver badges27 bronze badges asked Oct 12, 2016 at 10:39 MalasorteMalasorte 1,1837 gold badges23 silver badges47 bronze badges3 Answers
Reset to default 5Yes, it is possible and it is simplest with jquery.
You need to "get" contents of the text file like this:
$.get("www.example./page_b/my_file.txt", function(contents){
//contents variable now contains the contents of the textfile as string
//check if file contains the word Hello
var hasString = contents.includes("Hello");
//outputs true if contained, else false
console.log(hasString);
})
Try using jquery $.get()
$.get("text file path",function(textString) {
// handle the returned string ..
},"text/plain")
I am using indexOf() to search a string in a text file using JavaScript. Here is the code
$.get("www.example./page_b/my_file.txt", function(contents){
var str = "Hello";
if(contents.indexOf(str) != -1){
console.log(str + " found");
}
})
本文标签: jquerySearch inside txt file using javascriptStack Overflow
版权声明:本文标题:jquery - Search inside txt file using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744342889a2601584.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论