Skip to content

Instantly share code, notes, and snippets.

@MasahiroSakoda
Created April 22, 2013 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasahiroSakoda/5433711 to your computer and use it in GitHub Desktop.
Save MasahiroSakoda/5433711 to your computer and use it in GitHub Desktop.
Ajax function on jQuery 1.8 style by CoffeeScript
ajax_req = (param, beforeReq, doneReq, afterReq) ->
beforeReq = null if typeof beforeReq == 'undefined'
doneReq = null if typeof doneReq == 'undefined'
afterReq = null if typeof afterReq == 'undefined'
$.ajax 'http://www.example.com/blah',
type:'GET'
dataType:'json'
beforeSend: (jqXHR, settings) ->
console.log settings
beforeReq(settings)
.fail (jqXHR, textStatus, errorThrown) ->
console.log errorThrown
.done (data, textStatus, jqXHR) ->
console.log data
doneReq(data)
.always (data, textStatus, jqXHR) ->
console.log textStatus
afterReq(textStatus)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment