0

My code is :

 <script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
    //bit_url function
    function bit_url(url)
    {
        var url=url;
        var username="username"; // bit.ly username
        var key="bit.ly API key";
        $.ajax({
            url:"http://api.bit.ly/v3/shorten",
            data:{longUrl:url,apiKey:key,login:username},
            dataType:"jsonp",
            success:function(v)
            {
                var bit_url=v.data.url;
                $("#result").html('<a href="'+bit_url+'" target="_blank">'+bit_url+'</a>');
            }
        });
    }

    $("#short").click(function()
    {
        var url=$("#url").val();
        var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
        var urltest=urlRegex.test(url);
        if(urltest)
        {
            bit_url(url);
        }
        else
        {
            alert("Bad URL");
        }
    });
});
</script>

//HTML Code
<input type="text" name="url" id="url"/>
<input type="submit" id="short" value="Submit"/>
<div id="result"></div>`enter code here`

when I am giving this url then its neither giving error nor its giving short url. Please help me out to find the way to come out with this error.

Thank's in advance!

1 Answer 1

2

bit.ly does not encode localhost URLs any more - see this

Sign up to request clarification or add additional context in comments.

1 Comment

Thank's. Is there any other way for short url other than bit.ly which supports localhost

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.