在 WordPress 中更新页面后更改内容

问题描述 投票:0回答:0

我目前有一些工作中的 jQuery,每 3.5 秒重新加载一次内容。但是,我想知道是否有可能做到这一点,以便在 WordPress 中更新页面时,只有相关部分会自动更新,而不是每 3.5 秒不断检查一次?

jQuery(document).ready(function($) {
    var refreshInterval = 3500; // refresh interval in milliseconds
    var postId = <?php echo get_the_ID(); ?>; // get the post ID
    setInterval(function() {
        $.ajax({
            url: '<?php echo admin_url("admin-ajax.php"); ?>',
            type: 'POST',
            cache: false,
            data: {
                action: 'check_post_content',
                post_id: postId,
            },
            success: function(response) {
                if (response === 'changed') {
                    $('.sidebar .summary ul').load(window.location.href + ' .sidebar .summary ul');
                }
            },
        });
    }, refreshInterval);
});
jquery ajax wordpress advanced-custom-fields
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.