Skip to content

Instantly share code, notes, and snippets.

@asika32764
Created September 30, 2016 00:04
Show Gist options
  • Select an option

  • Save asika32764/942bed5c71b5a8c6eeb967bf0a72f2ec to your computer and use it in GitHub Desktop.

Select an option

Save asika32764/942bed5c71b5a8c6eeb967bf0a72f2ec to your computer and use it in GitHub Desktop.
function AjaxHelper() {
this.ajax = function(url, type, dataType, data, callback) {
$.ajax({
url: url,
type: type,
dataType: dataType,
data: data,
success: callback,
error: function(xhr, errorType, error) {
alert('Ajax request error, errorType: ' + errorType + ', error: ' + error)
}
})
}
}
AjaxHelper.prototype.get = function(url, data, callback) {
this.ajax(url, 'GET', 'json', data, callback)
}
AjaxHelper.prototype.post = function(url, data, callback) {
this.ajax(url, 'POST', 'json', data, callback)
}
AjaxHelper.prototype.put = function(url, data, callback) {
this.ajax(url, 'PUT', 'json', data, callback)
}
AjaxHelper.prototype.delete = function(url, data, callback) {
this.ajax(url, 'DELETE', 'json', data, callback)
}
AjaxHelper.prototype.jsonp = function(url, data, callback) {
this.ajax(url, 'GET', 'jsonp', data, callback)
}
AjaxHelper.prototype.constructor = AjaxHelper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment