-
-
Save rebaomi/8418603 to your computer and use it in GitHub Desktop.
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
cc.ajax = function (obj) { | |
var callback; // 非null表示外部已经调用了done操作。 | |
var result; // 非null表示AJAX操作已经结束。 | |
setTimeout(function () { | |
$.ajax(obj).done(function (res) { // AJAX操作完成时 | |
if (callback) { // 外面已经给了callback? | |
callback(res); // 那么直接调用 | |
} else { // 否则 | |
result = res; // 保留结果,等待外部done操作。 | |
} | |
}); | |
}, 100); | |
return { | |
done: function (cb) { // 外部done操作调用时 | |
if (result) { // 假如已经有了结果 | |
cb(result); // 那么直接调用done | |
} else { // 否则 | |
callback = cb; // 保留callback,等待AJAX操作结束 | |
} | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment