wrapperのwrapper…

 prototype.jsAjax.Requestクラスをラッピング。

var MyAjax = Class.create();
MyAjax.prototype = {
	initialize: function(url)
	{
		this.url = url;
	},
	get: function(h, block)
	{
		new Ajax.Request(this.url,
		{
			method: "get",
			parameters: $H(h).toQueryString(),
			onSuccess: block
		});
	},
	post: function(h, block)
	{
		new Ajax.Request(this.url,
		{
			method: "post",
			postBody: $H(h).toQueryString(),
			onSuccess: block
		});
	}
}
//var ajObj = new MyAjax(url);
//ajObj.get({"name":"taiyoh"}, function(o){...});
//若しくは
//ajObj.post({"q":"ブーーーーン"},function(o){...});

 どうせ再発明だろうけど。とりあえず

  • 毎回『new Ajax.Request』の長い記述はなぁ…。しかも使わないパラメータばっかだし(おい)
  • 表面上の動きは"get"も"post"も変わらないし(おい)
  • ってか、getとpostの指定は、そのままメソッ名にした方が分かりやすくね?
  • responseTextの処理は、もっとブロックっぽく記述できた方がカッコよくね?

 という些細な出来心からでした。