�Ȥ����櫓�ǡ��������Ƥߤޤ�����

snippets from shinichitomita��s journal - �ؿ�̾����Υ�����Хå���JSONP�ȸ������ȤˤĤ���
������С����ץ������ǹ�®��padding��ʬ��񤭴����륭��å��夬���äƤ⤤����ʡ��Ȼפä���������mod��뤫��

�Ȥ����Ϥ�������ñ��

http://server.whereever/path/to/jsonp2jsonp.cgi/callback_name/http://server.elsewhere/path/to/original/jsonp

��URI�˥���������������ǡ�http://server.elsewhere/path/to/original/jsonp�ν��Ϸ�̤�callback��̾����callback_name���Ѵ�����ޤ���

URL:
Callback Code:
Output:
CGI Source: http://www.dan.co.jp/~dankogai/cgi/jsonp2jsonp.src
Client Source:
<script language="JavaScript" src="http://www.kawa.net/works/js/jkl/share/jkl-dumper.js"></script>
<script>
function JSONP2JSONP(proxy, cb){
  this.proxy = proxy;
  this.cb    = (cb || 'jsonp');
  this.parse = function(uri, cb){
    if (! cb) cb = this.cb;
    var script = document.createElement('script'); 
    script.id = this.proxy + '/' + cb + '/' + uri;
    script.charset = 'UTF-8';
    script.src = script.id; 
    document.lastChild.appendChild(script);
  };
  return this;
}

function $(id){ return document.getElementById(id) }
var jsonp2jsonp = new JSONP2JSONP('http://www.dan.co.jp/~dankogai/cgi/jsonp2jsonp.cgi');
function eval_code(){
  try{
    eval($('code').value);
  }catch(e){
    alert(e); return;
  }
  $('code').value.match(/^([_0-9A-Za-z]+) /);
  var fname = RegExp.$1;
  // alert(fname);
  jsonp2jsonp.parse($('uri').value, fname);
}
</script>
<div style="border: dotted 1px; padding: 0.25em">
<dl>
<dt>URL:</dt>
<dd><input type="text" id="uri" size="64"
 value="http://www.dan.co.jp/~dankogai/yubin2jsonp/100/1000001.js"><dd>
<dt>Callback Code:</dt>
<dd><textarea id="code" cols="64" rows="4">
whatever_the_function_name_is = function(json){
  alert(json)
  // $('json').innerHTML = (new JKL.Dumper()).dump(json)
};
</textarea>
<dt>Output:</dt>
<dd><pre id="json"></pre></dd>
</dd>
</dl>
<input type="submit" onclick="eval_code()" >
<input type="submit" onclick="json.innerHTML=''" value="clear output">
</div>

Enjoy!

Dan the Javascripting Perl Monger