jQuery��Ȥä�jsonp�ǥǡ���������
�Ȥꤢ�����饤�֥��ˤ��ƻȤ��Ȥ������ɤ߹��फ�󤸤ˡ�
bitlyApi.js
BitlyClient = function() { this._initialize(); } $.extend(BitlyClient.prototype, { _initialize: function(login, apikey, version) { this.login = login || "LOGIN"; this.apikey = apikey || "APIKEY"; this.version = version || "2.0.1"; }, shorten: function(longUrl, target) { var result; $.ajax({ type: "GET", url: "http://api.bit.ly/shorten", data: { "login": this.login, "apiKey": this.apikey, "version": this.version, "longUrl": longUrl }, dataType: "jsonp", success: function(data) { for (var r in data.results) { result = data.results[r]; break; }; target.text(result.shortUrl); } }); }, expand: function(shortUrl, target) { var result; $.ajax({ type: "GET", url: "http://api.bit.ly/expand", data: { "login": this.login, "apiKey": this.apikey, "version": this.version, "shortUrl": shortUrl }, dataType: "jsonp", success: function(data) { for (var r in data.results) { result = data.results[r]; break; }; target.text(result.longUrl); } }); } }); var Bitly = new BitlyClient();
URL�ȥ������å��Ϥ��ƽ��Ϥ���饤�֥��ʤΤǻȤ����Ӥ˹�碌�ơ�
�Ȥꤢ����URL���Ϥ��ƽ��Ϥ����㡣
html
<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></script> <script src="bitlyApi.js" type="text/javascript"></script> <script type="text/javascript"> $(function() { $('input[id^=bitly]').click(function() { eval("Bitly."+$(this).val()+"($('input#url').val(), $('div#bitly-result'))"); }); }); </script> </head> <body> <input type="text" id="url" /><input type="button" value="shorten" id="bitly-shorten" /><input type="button" value="expand" id="bitly-expand" /> <div id="bitly-result"></div>