Created
July 28, 2013 20:44
-
-
Save ezos86/6100153 to your computer and use it in GitHub Desktop.
Basic API Get Request Javascript (no jquery)
This file contains 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> | |
<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