Created
April 22, 2013 10:06
-
-
Save MasahiroSakoda/5433711 to your computer and use it in GitHub Desktop.
Ajax function on jQuery 1.8 style by CoffeeScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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