Getting TinyUrl in Javascript

javascript

Solution

The API you are using is not returning the shortened URL as JSON but as plain text. And there is no way to extract plain text data from another domain (here tinyurl) with an AJAX call. See same origin policy.

If all you want to do is shorten an URL client-side, bit.ly has an API that supports JSONP.

$.getJSON('http://api.bitly.com/v3/shorten?callback=?',
    {
        format: "json",
        apiKey: YOUR_API_KEY,
        login: YOUR_LOGIN,
        longUrl: "http://link.to.be/shortened"
    },
    function(response) {
        console.log(response.data.url);
    }
);

Problem

``` function ShortUrl(bigurl) { $.getJSON( "http://tinyurl.com/api-create.php", url: 'http://dfsghdsvfbjvjd.com', function(data){ alert(data); }); } ``` Not Working ``` $['getJSON']('http://tinyurl.com/api-create.php?url=http://xxxxxxx.com/', function (a) { h = a; alert (h); }); ``` This Call is Also Not Working. Tried Various calls but not getting tinyurl.

Original source