Created
July 28, 2013 21:38
-
-
Save ezos86/6100362 to your computer and use it in GitHub Desktop.
Basic API Get Request Javascript only --> Replace username and password
--> Use Base64.js file with this
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
function make_base_auth(user, pass) { | |
var tok = user + ':' + pass; | |
var hash = Base64.encode(tok); | |
return "Basic " + hash; | |
} | |
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/api/accounts/me",true); | |
xhr.setRequestHeader('Authorization', make_base_auth('username','password')); | |
xhr.send(); | |
xhr.onload = function(){ | |
console.log(xhr.responseText); | |
var data = $.parseJSON(xhr.responseText); | |
console.log(data.email); | |
document.getElementById("myDiv").innerHTML= data.email; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment