Skip to content

Instantly share code, notes, and snippets.

@robinboehm
Created March 3, 2014 10:21
Show Gist options
  • Save robinboehm/9322143 to your computer and use it in GitHub Desktop.
Save robinboehm/9322143 to your computer and use it in GitHub Desktop.
Workshop makeHTTPRequest 03/14
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Q Beispiel</title>
<script src="bower_components/q/q.js"></script>
</head>
<body>
<header>
<h1>Q Beispiel</h1>
</header>
<script>
function makeHttpRequest(url, callbackFn) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onload = function() {
if (xhr.status === 200) {
callbackFn(xhr.responseText);
} else {
throw new Error('Status code was ' + xhr.status);
}
};
xhr.onerror = ...;
xhr.onprogress = ...;
xhr.send();
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment