Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- function readTextFile(file)
- {
- //alert("test");
- var rawFile = new XMLHttpRequest();
- rawFile.open("GET", file, false);
- rawFile.onreadystatechange = function ()
- {
- if(rawFile.readyState === 4)
- {
- if(rawFile.status === 200 || rawFile.status == 0)
- {
- var allText = rawFile.responseText;
- allTextArray = allText.split('\n');
- //alert(allText);
- var randomLine = Math.floor( Math.random() * allTextArray.length );
- //alert(allTextArray[randomLine]);
- document.getElementById("test").innerHTML=allTextArray[randomLine];
- return allTextArray[randomLine];
- }
- }
- }
- rawFile.send(null);
- }
- </script>
- <script>
- function test()
- {
- alert(readTextFile('test.txt'));
- document.getElementById("test2").innerHTML= readTextFile('test.txt');
- }
- </script>
- <button id="button_feedback" onclick="readTextFile('test.txt')"> test </button>
- <button id="button_feedback2" onclick="test()"> test2 </button>
- <div id="test">test</div>
- <div id="test2">test2</div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement