Created
December 17, 2015 03:01
-
-
Save yulanggong/dd0b1b914c6cced7baf6 to your computer and use it in GitHub Desktop.
Fake AJAX
This file contains hidden or 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
//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