-
-
Save wolfkarl/5949730 to your computer and use it in GitHub Desktop.
Ajax Raw und jQuery (noch async.php anlegen!!)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr"> | |
| <head> | |
| <meta http-equiv="content-type" content="text/html; charset=utf-8" /> | |
| <title>AJAX Demo</title> | |
| </head> | |
| <body> | |
| <h1>huuuuui Ajax!</h1> | |
| <form method="get"> | |
| <input type="text" size="60" name="texmex" id="texmex" readonly="readonly" ><br> | |
| <input type="button" value="RAW Ajax" onclick="ajax_raw();"> | |
| <input type="button" value="jQuery Ajax" onclick="ajax_jquery();"> | |
| <script type="text/javascript"> | |
| function ajax_jquery() | |
| { | |
| $.get("async.php", function (data) { | |
| $("#texmex").val(data + " (via jQuery)"); | |
| }); | |
| } | |
| function ajax_raw() | |
| { | |
| // Request Objekt Anlegen | |
| var httpRequest; | |
| if (window.XMLHttpRequest) { // Mozilla, Safari, ... | |
| httpRequest = new XMLHttpRequest(); | |
| } else if (window.ActiveXObject) { // IE 8 und so | |
| httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); | |
| } | |
| // funktion erstellen, die aufgerufen wird wenn | |
| // das req.o. request abschliesst | |
| httpRequest.onreadystatechange = function(){ | |
| if (httpRequest.readyState === 4) | |
| { | |
| // http Request vollstaendig abgewickelt | |
| if (httpRequest.status === 200) | |
| { | |
| document.getElementById("texmex").value = (httpRequest.responseText) + " (via raw ajax)"; | |
| } | |
| else | |
| { | |
| alert("error!"); | |
| } | |
| } | |
| }; | |
| httpRequest.open('GET', 'async.php', true); | |
| httpRequest.send(null); | |
| // (nun wird die Funktion oben aufgerufen!) | |
| } | |
| </script> | |
| <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> | |
| </form> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment