[Rest] 分享下jquery.rest

gdsean 2009-09-10
找到一端jquery做rest客户端调用的api

// jQuery - Rest - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)

;(function($){
 
  // --- Version
 
  $.rest = $.json = { version : '1.1.0' }
 
  $.json.post = $.create = function(uri, data, callback) {
    return $.post(uri, data, callback, 'json')
  }
 
  $.json.get = $.read = function(uri, data, callback) {
    return $.getJSON(uri, data, callback)
  }

  $.json.put = $.update = function(uri, data, callback) {
    if ($.isFunction(data)) callback = data, data = {}
    return $.post(uri, $.extend(data, { _method: 'put' }), callback, 'json')
  }
 
  $.json.del = $.del = $.destroy = function(uri, data, callback) {
    if ($.isFunction(data)) callback = data, data = {}
    return $.post(uri, $.extend(data, { _method: 'delete' }), callback, 'json')
  }
 
})(jQuery)

http://jetpackweb.com/blog/2009/09/09/unobtrusive-restful-jquery/
Global site tag (gtag.js) - Google Analytics