1
我正在嘗試修改一個Wordpress插件,以便它不會頻繁執行admin-ajax.php腳本。該插件在頁面上顯示輪詢 - 它在文檔準備就緒後異步加載它們。有問題的腳本是下面寫的async-load.js。現在.load在for循環中用於顯示頁面上的每個輪詢(每個頁面有多個輪詢)。這會爲頁面上的每個輪詢執行admin-ajax腳本 - 例如,如果有10次輪詢腳本被執行了10次。Jquery .load - 同時具有不同數據的多個ID - Wordpress
我想知道是否可以修改腳本,以便它只顯示一個admin-ajax.php腳本執行的所有輪詢。
這裏是全碼:
if (window['tp_async_polls']) {
jQuery(document).ready(function ($) {
var pollContainer = [];
var pollID = [];
$(tp_async_polls).each(function (index, poll) {
//tp_async_polls gives an array of object with keys id and container
pollContainer.push(poll.container);
//store each poll's container id in array
pollID.push(poll.id);
//store each poll's id in array
});
for (i=1; i < pollContainer.length; i++) {
//loop through polls and display them - here the admin-ajax.php gets executed for every poll that is on a page. Looking for solution to only execute it once per page load.
$(pollContainer[i]).load(totalpoll_cache_compatibility.ajaxurl, {action: 'load_tp', tp_poll_id: pollID[i]}, function() {
FastClick.attach(this);
$(this).animateVotesBar();
});
};
});
};
任何建議是值得歡迎的。謝謝你的幫助。