Advertisement
LukasHuhn

DigicampusPlanKlauen

Apr 17th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html><!-- example.html : public domain -->
  2. <body>
  3. <script language="JavaScript" type="text/JavaScript" >
  4. function alertContents(httpRequest) {
  5.   if (httpRequest.readyState == 4) {
  6.     // everything is good, the response is received
  7.     if ((httpRequest.status == 200) || (httpRequest.status == 0)) {
  8.       // FIXME: perhaps a better example is to *replace* some text in the page.
  9.       var htmlDoc = document.createElement('div'); // Create a new, empty DIV node.
  10.       htmlDoc.innerHTML = httpRequest.responseText; // Place the returned HTML page inside the new node.
  11.       //alert("The response was: " + httpRequest.status + httpRequest.responseText);
  12.       document.getElementById("show").innerHTML = '<textarea rows="30" cols="50">'+httpRequest.status + httpRequest.responseText+"</textarea>";
  13.     } else {
  14.       alert('There was a problem with the request. ' + httpRequest.status + httpRequest.responseText);
  15.     }
  16.   }
  17. }
  18. function send_with_ajax() {
  19.   var the_url = getURL();
  20.   var httpRequest = new XMLHttpRequest();
  21.   httpRequest.onreadystatechange = function() { alertContents(httpRequest); };  
  22.   httpRequest.open("GET", the_url, true);
  23.   httpRequest.send();
  24. }
  25.  var url = "https://digicampus.uni-augsburg.de/";
  26. function getURL( ){
  27.     return url;
  28. }
  29. function setURL(){
  30.     url = document.getElementById("url").value;
  31.     document.getElementById("demo").value = getURL();
  32. }
  33. function httpGet()
  34. {
  35.     var xmlHttp = getURL();
  36.  
  37.     xmlHttp = new XMLHttpRequest();
  38.     xmlHttp.open( "GET", theUrl, false );
  39.     xmlHttp.send( null );
  40.     document.getElementById("demo").innerHTML = xmlHttp.status + xmlHttp.responseText;
  41.     //return xmlHttp.responseText;
  42. }
  43. </script>
  44.  
  45. <input onClick="setURL()" type="text" value="URL eingeben" id="url">
  46. <br>
  47. <input onClick="send_with_ajax()" type="button" value="Click me!" id="demo">
  48. <p id="show"></p>
  49. <script>
  50.     document.getElementById("demo").value = getURL();
  51. </script>
  52.  
  53. </body>
  54. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement