Question

I'm having a strange issue with an error while working with the bit.ly api that says:

"Uncaught TypeError: Illegal invocation"

It seems to be an issue with the "long_url" variable, when I set it as a string, such as "http://www.google.com" it works, and returns the shortened url into the console, but if I set it to "window.location" it doesn't.

I can't see why it doesn't work (unless I'm being a bit thick)... any help will be much appreciated.

Code is below:

    function get_short_url(long_url, login, api_key, func)
    {//use bit.ly api to get shortlink of item on share button hover
        $.getJSON(
            "http://api.bitly.com/v3/shorten?callback=?", 
            { 
                "format": "json",
                "apiKey": api_key,
                "login": login,
                "longUrl": long_url
            },
            function(response)
            {
                func(response.data.url);
            }
        );
    }

    //bit.ly details
    var login = "XXXXX";
    var api_key = "XXXXX";
    var long_url = window.location;

    get_short_url(long_url, login, api_key, function(short_url) {
        console.log(short_url);
    });
Was it helpful?

Solution

Try this instead...

var long_url = window.location.toString();

window.location is an object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top