Wordpressプラグインを変更して、admin-ajax.phpスクリプトをあまり頻繁に実行しないようにしようとしています。プラグインはページ上にポーリングを表示します。ドキュメントの準備が整うと、ポーリングは非同期にロードされます。問題のスクリプトは以下のasync-load.jsです。これで、.loadはforループ内でページ上の各ポーリングを表示するために使用されます(各ページには複数のポーリングがあります)。これは、ページ上のすべてのポーリングに対してadmin-ajaxスクリプトを実行します。たとえば、ポーリングが10回ある場合、スクリプトは10回実行されます。JQuery .load - 一度に異なるデータを持つ複数のID - Wordpress
1つの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();
});
};
});
}。
ご提案は大歓迎です。ご協力いただきありがとうございます。