Created
March 29, 2010 23:02
-
-
Save kilaulena/348527 to your computer and use it in GitHub Desktop.
This file contains 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
// before: | |
function ajax(obj, options, errorMessage, ajaxOptions) { | |
options = $.extend({successStatus: 200}, options); | |
errorMessage = errorMessage || "Unknown error"; | |
$.ajax($.extend($.extend({ | |
type: "GET", dataType: "json", | |
complete: function(req) { | |
var resp = $.httpData(req, "json"); | |
if (req.status == options.successStatus) { | |
if (options.success) options.success(resp); | |
} else if (options.error) { | |
options.error(req.status, resp.error, resp.reason); | |
} else { | |
alert(errorMessage + ": " + resp.reason); | |
} | |
} | |
}, obj), ajaxOptions)); | |
} | |
// after: | |
function ajax(obj, options, errorMessage, ajaxOptions) { | |
options = $.extend({successStatus: 200}, options); | |
errorMessage = errorMessage || "Unknown error"; | |
$.ajax($.extend($.extend({ | |
type: "GET", dataType: "json", | |
complete: function(req) { | |
var resp = $.httpData(req, "json"); | |
if (options.ajaxStart) { | |
options.ajaxStart(resp); | |
} | |
if (req.status == options.successStatus) { | |
if (options.success) options.success(resp, obj); | |
} else if (options.error) { | |
options.error(req.status, resp.error, resp.reason); | |
} else { | |
alert(errorMessage + ": " + resp.reason); | |
} | |
} | |
}, obj), ajaxOptions)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment