小编Mis*_*yng的帖子

如何在 WordPress 中定期使用 jQuery 调用 Ajax?

我想每 30 秒更新一次 WordPress 小部件中的信息。因此我想我最好使用一些 Ajax。

我在WordPress Codex上找到了这个并将其添加到我的functions.php:

add_action( 'admin_footer', 'my_action_javascript' ); // Write our JS below here

function my_action_javascript() { ?>
<script type="text/javascript" >
jQuery(document).ready(function($) {

    var data = {
               'action': 'my_action',
               'whatever': 1234
    };

    // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
    jQuery.post(ajaxurl, data, function(response) {
        alert(response);
    });
});
</script> <?php
}

add_action( 'wp_ajax_my_action', 'my_action_callback' );

    function my_action_callback() {
    global $wpdb; // this is how you get access to …
Run Code Online (Sandbox Code Playgroud)

javascript ajax wordpress jquery

1
推荐指数
1
解决办法
842
查看次数

标签 统计

ajax ×1

javascript ×1

jquery ×1

wordpress ×1