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();
});
};
});
};
任何建议是值得欢迎的。谢谢你的帮助。