AjaxDelegate Demo

Basic usage
var delegator = new AjaxDelegate("dataText.php", "", function(data){ console.log(data); });
delegator.load();
(new AjaxDelegate("dataText.php", "", function(data){ console.log(data); })).load();
or
var delegator = new AjaxDelegate();
delegator.url = "dataText.php";
delegator.successCB = function(data){ console.log(data); }
delegator.load();
Set callback functions
var delegator = new AjaxDelegate("dataText.php", "", ajaxDelegateSuccess, ajaxDelegateError);
delegator.load();
Set parameters
var params = {};
params.param1 = Math.round(Math.random() * 10000);
params.param2 = "some text";
var delegator = new AjaxDelegate("dataText.php", params, ajaxDelegateSuccess, ajaxDelegateError);
delegator.load();
Set method to GET (default is POST)
var params = {};
params.param1 = Math.round(Math.random() * 10000);
params.param2 = "some text";
var delegator = new AjaxDelegate("dataText.php", params, ajaxDelegateSuccess, ajaxDelegateError);
delegator.method = "GET";
delegator.load();
Load JSON data
var params = {};
params.param1 = Math.round(Math.random() * 10000);
params.param2 = "some text";
var delegator = new AjaxDelegate("dataJson.php", params, ajaxDelegateSuccess, ajaxDelegateError);
delegator.dataType = "JSON";
delegator.load();
Store local data
var params = {};
params.param1 = Math.round(Math.random() * 10000);
params.param2 = "some text";
var delegator = new AjaxDelegate("dataJson.php", params, ajaxDelegateSuccess, ajaxDelegateError);
delegator.dataType = "JSON";
delegator.prop.idx = 123;
delegator.prop.value = 456;
delegator.load();
Show loading layer
var params = {};
params.param1 = Math.round(Math.random() * 10000);
params.param2 = "some text";
var delegator = new AjaxDelegate("dataJson.php", params, ajaxDelegateSuccess, ajaxDelegateError);
delegator.dataType = "JSON";
delegator.loading = true;
delegator.load();

go to Hangun's World Blog