Skip to content

Instantly share code, notes, and snippets.

@helloGoGo
Last active March 8, 2017 07:04
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 helloGoGo/fa7f967dcd9d8084f59eb7b246732065 to your computer and use it in GitHub Desktop.
Save helloGoGo/fa7f967dcd9d8084f59eb7b246732065 to your computer and use it in GitHub Desktop.
Deferredを用いたajax共通オブジェクト
var getData = function (query) {
var param = {
url: 'http://hoge',
data: {
userId : 'hoge'
query: query,
},
dataType: 'json'
}
//success
Http.get(param).done(function(data) {
console.log(data);
});
//fail
Http.get(param).fail(function(data) {
console.log('fail');
});
}
//common
var Http = {
var defer = $.Deferred();
get : function (param) {
$.ajax({
url: param.url,
data: param.data || '',
dataType: param.dataType || '',
success: defer.resolve,
error: defer.reject
});
return defer.promise();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment