Skip to content

Instantly share code, notes, and snippets.

@ezos86
Created July 28, 2013 20:44
Show Gist options
  • Save ezos86/6100153 to your computer and use it in GitHub Desktop.
Save ezos86/6100153 to your computer and use it in GitHub Desktop.
Basic API Get Request Javascript (no jquery)
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
function api_call(){
var xhr;
// code for IE 10, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest){
xhr=new XMLHttpRequest();
}
xhr.open("GET","https://api.qpme.com/1.6/locations",true);
xhr.send();
xhr.onload = function(){
console.log(xhr.responseText);
var data = $.parseJSON(xhr.responseText);
console.log(data[0].address);
document.getElementById("myDiv").innerHTML= data[1].address;
}
}
</script>
</head>
<body>
<h3>Basic API Get Call - Javascript (no Jquery)</h3>
<button type="button" onclick="api_call()">Request data</button>
<div style="border: 1px solid #ccc; height:100px; " id="myDiv"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment