Facebook
From Colorant Mousedeer, 6 Years ago, written in HTML5.
Embed
Download Paste or View Raw
Hits: 276
  1. <!DOCTYPE html>
  2. <meta charset="utf-8">
  3. <title>AJAX</title>
  4. </head>
  5. <button type="button" onclick="pobierz_dane()">Pobierz plik</button>
  6. <p>Zawartość pliku</p>
  7. <div id="kontener"></div>
  8. function pobierz_dane(){
  9.         var xhttp = new XMLHttpRequest();
  10.         xhttp.onreadystatechange = function(){
  11.                 if (this.readyState == 4 && this.status == 200) {
  12.                         wyswietl_odpowiedz(this.responseText);
  13.                 }
  14.         };
  15.         xhttp.open("POST", "slowa.txt", true);
  16.         xhttp.send();
  17. }
  18. function wyswietl_odpowiedz(plik){
  19. var linie_pliku = plik.split("\r\n");
  20.         alert(linie_pliku[0].charAt(0))
  21.         var kontener = document.getElementById("kontener");
  22.         var slowa="";
  23.                 for(var i=0;i<linie_pliku.length;i++){
  24.                         if(linie_pliku[i].charAt(0)=="A")
  25.                         {slowa=slowa+linie_pliku[i]+"<br>"
  26.                         }
  27.                 }
  28.         kontener.innerHTML=slowa;
  29. }
  30. </body>
  31. </html>