Skip to content

Instantly share code, notes, and snippets.

@yulanggong
Created December 17, 2015 03:01
Show Gist options
  • Save yulanggong/dd0b1b914c6cced7baf6 to your computer and use it in GitHub Desktop.
Save yulanggong/dd0b1b914c6cced7baf6 to your computer and use it in GitHub Desktop.
Fake AJAX
//Fake AJAX
$.fajax = function(options){
options = $.extend({
fTime: 16, //delay time
fData: {status: 1}, //response data
fDone: true //success or not
}, options);
return new $.Deferred(function(dfd){
setTimeout(function(){
if(options.fDone){
options.success && options.success(options.fData);
dfd.resolve(options.fData);
} else {
options.error && options.error({});
dfd.reject({});
}
}, options.fTime);
}).promise();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment