Skip to content

Instantly share code, notes, and snippets.

@wolfkarl
Created July 8, 2013 12:52
Show Gist options
  • Save wolfkarl/5948529 to your computer and use it in GitHub Desktop.
Save wolfkarl/5948529 to your computer and use it in GitHub Desktop.
simple ajax request --> alert
<script type="text/javascript">
// Request Objekt Anlegen
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 8 and older
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)
{
alert(httpRequest.responseText);
}
else
{
alert("error!");
}
}
};
httpRequest.open('GET', 'async.php', true);
httpRequest.send(null);
// (nun wird die Funktion oben aufgerufen!)
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment