Created
November 6, 2012 08:35
-
-
Save vinitkumar/4023498 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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