Is Ajax in WordPress

后端 未结 7 1055
萌比男神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 17:58

    I am not sure if WordPress has a function for this but it can be done by creating a simple one yourself.

    if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
    {
        // Is AJAX request
        return true; 
    }
    

提交回复
热议问题