Is Ajax in WordPress

后端 未结 7 1040
萌比男神i
萌比男神i 2021-01-03 17:23

Is there anyway to detect if the current server operation is currently an AJAX request in WordPress?

For example:

is_ajax()
7条回答
  •  情歌与酒
    2021-01-03 18:15

    Update: since WordPress 4.7.0 you can call a function wp_doing_ajax(). This is preferable because plugins that "do Ajax" differently can filter to turn a "false" into a "true".


    Original answer:

    If you're using Ajax as recommended in the codex, then you can test for the DOING_AJAX constant:

    if (defined('DOING_AJAX') && DOING_AJAX) { /* it's an Ajax call */ }
    

提交回复
热议问题