2016-10-12 17 views
0

www.example.com/page_a/www.example.com/page_b/にあるファイル内で「hello」というテキストを検索するjavascriptコードを実行することは可能ですmy_file.txtjavacriptを使用してtxtファイル内を検索する

これはjavascript/jquery /他のjavascriptフレームワークで可能ですか?

答えて

4

を使用してみてくださいはい、それは可能であり、それはjQueryを使って最も簡単です。

$.get("www.example.com/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); 
}) 
:あなたはこのようなテキストファイルの内容を「取得」する必要が

2

はjqueryの$に.get()

$.get("text file path",function(textString) { 
    // handle the returned string .. 
},"text/plain") 
関連する問題