Skip to content

Instantly share code, notes, and snippets.

@vinitkumar
Created November 6, 2012 08:35
Show Gist options
  • Save vinitkumar/4023498 to your computer and use it in GitHub Desktop.
Save vinitkumar/4023498 to your computer and use it in GitHub Desktop.
function img (url){
var short,ul="";
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyD1xzZ9B4NElbFAAz8IAhH9Ko1nbap28OU', 'false');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function () {
"use strict";
if (xhr.readyState === 4) {
short = JSON.parse(xhr.responseText);
ul = short.id;
console.log(ul);
return ul;
}
}
xhr.send(
JSON.stringify(
{
longUrl: url
}
)
);
console.log(typeof(ul));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment