
Untitled
By: a guest on
May 2nd, 2012 | syntax:
None | size: 0.90 KB | hits: 11 | expires: Never
// ajax utils
//
Dao.ajax = function(options){
var ajax = {};
ajax.type = options.type;
ajax.url = options.url;
ajax.dataType = 'json';
ajax.cache = false;
if(options.async==false || options.sync==true){
ajax.async = false;
};
if(ajax.type == 'POST' || ajax.type == 'PUT'){
ajax.data = jq.toJSON(options.data || {});
} else {
ajax.data = (options.data || {});
};
ajax.contentType = (options.contentType || 'application/json; charset=utf-8');
ajax.success = (options.success || function(){});
jq.ajax(ajax);
};
// meta-program Api.get(...), Api.post(...)
//
for(var i = 0; i < Dao.Api.modes.length; i++){
(function(){
var mode = Dao.Api.modes[i];
Dao[mode] = function(options){
options.type = mode.toUpperCase();
Dao.ajax(options);
};
})();
}