Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html><!-- example.html : public domain -->
- <body>
- <script language="JavaScript" type="text/JavaScript" >
- function alertContents(httpRequest) {
- if (httpRequest.readyState == 4) {
- // everything is good, the response is received
- if ((httpRequest.status == 200) || (httpRequest.status == 0)) {
- // FIXME: perhaps a better example is to *replace* some text in the page.
- var htmlDoc = document.createElement('div'); // Create a new, empty DIV node.
- htmlDoc.innerHTML = httpRequest.responseText; // Place the returned HTML page inside the new node.
- //alert("The response was: " + httpRequest.status + httpRequest.responseText);
- document.getElementById("show").innerHTML = '<textarea rows="30" cols="50">'+httpRequest.status + httpRequest.responseText+"</textarea>";
- } else {
- alert('There was a problem with the request. ' + httpRequest.status + httpRequest.responseText);
- }
- }
- }
- function send_with_ajax() {
- var the_url = getURL();
- var httpRequest = new XMLHttpRequest();
- httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
- httpRequest.open("GET", the_url, true);
- httpRequest.send();
- }
- var url = "https://digicampus.uni-augsburg.de/";
- function getURL( ){
- return url;
- }
- function setURL(){
- url = document.getElementById("url").value;
- document.getElementById("demo").value = getURL();
- }
- function httpGet()
- {
- var xmlHttp = getURL();
- xmlHttp = new XMLHttpRequest();
- xmlHttp.open( "GET", theUrl, false );
- xmlHttp.send( null );
- document.getElementById("demo").innerHTML = xmlHttp.status + xmlHttp.responseText;
- //return xmlHttp.responseText;
- }
- </script>
- <input onClick="setURL()" type="text" value="URL eingeben" id="url">
- <br>
- <input onClick="send_with_ajax()" type="button" value="Click me!" id="demo">
- <p id="show"></p>
- <script>
- document.getElementById("demo").value = getURL();
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement