Skip to content

Instantly share code, notes, and snippets.

@rosd89
Last active March 13, 2019 06:15
Show Gist options
  • Save rosd89/37095fe78fcc9602e3deac401998e8a3 to your computer and use it in GitHub Desktop.
Save rosd89/37095fe78fcc9602e3deac401998e8a3 to your computer and use it in GitHub Desktop.
/**
* Ajax
*/
function AjaxProcess(type, url, params, dataType, success, fail) {
this.type = type;
this.url = url;
this.params = params;
this.dataType = dataType;
this.onSuccess = success;
this.onFail = fail;
}
/**
* Ajax 프로토타입
*/
AjaxProcess.prototype = {
/**
* ajax실행 함수
*/
ajaxAct: function () {
var nullCheck = true;
//null 체크
if (!this.type
|| !this.url
|| !this.dataType) {
nullCheck = false;
}
//ajax실행
if (nullCheck) {
var act = this;
$.ajax({
type: act.type,
url: act.url,
dataType: act.dataType,
data: act.params,
success: function (data) {
act.onSuccess(data);
},
error: function (request, status, error) {
act.onFail(request, status, error);
}
});
}
}
};
/**
* 사용법
*/
new AjaxProcess('HTTP METHOD', 'URL', 'params', 'Return DataType', function (data) {
// Success Callback
}, function (request, status, error) {
// Error Callback
}).ajaxAct();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment