Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <!-- urządzenia mobilne -->
- <!-- <meta name="viewport" content="width=device-width, initial-scale=1"> -->
- <!-- wymuszenie na IE aby używał najnowszej wersji silnika renderującego stronę -->
- <!-- <meta http-equiv="X-UA-Compatible" content="IE=edge"> -->
- <meta charset="utf-8">
- <title>DIV 2</title>
- </head>
- <body>
- <div id="demo">
- <h2>XMLHttpRequest Object</h2>
- <button type="button" onclick="f1()">Pobierz treść</button>
- </div>
- <script>
- function f1() {
- var xhttp = new XMLHttpRequest();
- xhttp.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200) { //4 -żądanie zakonczone, odpowiedz serwera gotowa; 200 - OK
- document.getElementById("demo").innerHTML =
- this.responseText; //jako tekst JS //responseXML - jako XML
- }
- };
- xhttp.open("GET", "ajaxplik.txt", true); //open(method, url, async) //GET (proste w użyciu)/POST //url pliku //true - asynch. false synch.
- xhttp.send(); //wysyła żądanie do serwera
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement