[英]Codio Guide Throbber: Is there an open source jQuery version?
[英]Add throbber to jQuery post()
我發布ajax帖子時顯示出了不安。 以下是我的操作方式。 我想使代碼更簡潔。 我可以擴展$ .post這樣做嗎? 還有其他選擇嗎? 謝謝
//myThrobber is an object that displays a throbber in the center of the page
myThrobber.start();
$.post('somePage.php',myData,function (json){
myThrobber.stop();
//do whatever
},'json');
這就是我寫包裹在$.post
周圍的postThrob
函數的方式。
$.fn.postThrob = function (throbber, url, data, callback) {
throbber.start();
$.post(url, data, function (response) {
callback(response);
throbber.stop();
});
};
因此,現在您可以使用$.postThrob
代替$.post
。 只需將您的throbber對象作為第一個參數傳入即可。
如果您不想傳入更麻煩的obj,則可以使用全局變量,盡管它不太理想。 只是不要在函數本身內部創建對象。
我仍然看不出這樣做的價值;(
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.