你好,我正在開發一個 PHP 項目,我需要使用 ajax 請求加載一些請求。以下是我的請求功能。功能一:當showNotify事件被點擊時,我調用ajax請求來獲取內容并使用ajaxStart來顯示旋轉器,直到內容完全準備好! //* First click load nofication$(document).on('click', '#showNotify', function() { let check = $(this).data('check'); if(check === 0) { //* Process notification $(this).attr('data-check', 1); //* Load ajax request $(document).ajaxStart(function() { $('#notify-wait').show(); }); $(document).ajaxComplete(function() { $('#notify-wait').hide(); $('#list-noti').show(); }); $.ajax({ url: '/list-dd-notifications', method: 'GET', success: function() { $('#notif-unread').hide(); } }); }});功能二:我需要從服務器端檢查用戶是否有新的未就緒通知并顯示新的通知標志。function checkNewFotify() { $.ajax({ url: '/check-notifications', method: 'GET', success: function(data) { if(data) { if($('#notif-unread').is(":hidden")) { $('#notif-unread').show(); } } else { if($('#notif-unread').is(":visible")) { $('#notif-unread').hide(); } } } });}//* check for new notificationsetInterval(() => { checkNewFotify();}, 5000);問題:每當 showNotify 首先下拉時,它都會向旋轉器顯示加載程序,直到請求完全加載,如果checkNewFotify函數正在執行的工作是每 5 秒刷新一次以檢查服務器是否有新通知,則showNotify中的 ajaxStart將受到影響每次 checkNewFotify在后臺刷新時顯示旋轉加載程序。請問我怎樣才能阻止它顯示旋轉加載器,同時它每 5 秒刷新一次。
1 回答

紫衣仙女
TA貢獻1839條經驗 獲得超15個贊
將 ajax 上的全局選項設置為 falsecheckNewFotify()將阻止像 ajaxStart 這樣的處理程序觸發。
$.ajax({
url: '/check-notifications',
method: 'GET',
global: false,
});
- 1 回答
- 0 關注
- 133 瀏覽
添加回答
舉報
0/150
提交
取消