Skip to content

Instantly share code, notes, and snippets.

@ezos86
Created July 28, 2013 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezos86/6100362 to your computer and use it in GitHub Desktop.
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
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