2011-11-01 150 views

回答

2

我在這裏做一個小提琴:http://jsfiddle.net/duotrigesimal/XB8Uf/

這使得在LongURL(http://longurl.org/api#expand-url)到API的請求,以獲得展開網址。

我也使用jQuery在這個例子中,但你可以把它無需如果需要工作。

var tests = [ 
    'http://t.co/NJwI2ugt', 
    'http://www.google.com' //nothing should happen 
]; 

for(i in tests) { 

    var data = { 
     url: tests[i], 
     format: 'json' 
    }; 

    $.ajax({ 
     dataType: 'jsonp', 
     url: 'http://api.longurl.org/v2/expand', 
     data: data, 
     success: function(response) { 
      $('#output').append(response['long-url']+'<br>'); 
     } 

    }); 

}