Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.90 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.   // ajax utils
  2.   //
  3.     Dao.ajax = function(options){
  4.       var ajax = {};
  5.       ajax.type = options.type;
  6.       ajax.url = options.url;
  7.       ajax.dataType = 'json';
  8.       ajax.cache = false;
  9.       if(options.async==false || options.sync==true){
  10.         ajax.async = false;
  11.       };
  12.       if(ajax.type == 'POST' || ajax.type == 'PUT'){
  13.         ajax.data = jq.toJSON(options.data || {});
  14.       } else {
  15.         ajax.data = (options.data || {});
  16.       };
  17.       ajax.contentType = (options.contentType || 'application/json; charset=utf-8');
  18.       ajax.success = (options.success || function(){});
  19.       jq.ajax(ajax);
  20.     };
  21.  
  22.   // meta-program Api.get(...), Api.post(...)
  23.   //
  24.     for(var i = 0; i < Dao.Api.modes.length; i++){
  25.       (function(){
  26.         var mode = Dao.Api.modes[i];
  27.  
  28.         Dao[mode] = function(options){
  29.           options.type = mode.toUpperCase();
  30.           Dao.ajax(options);
  31.         };
  32.       })();
  33.     }