Is Ajax in WordPress

后端 未结 7 1035
萌比男神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:01

    To see if the current request is an AJAX request sent from a js library ( like jQuery ), you could try something like this:

    if( ! empty( $_SERVER[ 'HTTP_X_REQUESTED_WITH' ] ) &&
          strtolower( $_SERVER[ 'HTTP_X_REQUESTED_WITH' ]) == 'xmlhttprequest' ) {
        //This is an ajax request.
    }
    

提交回复
热议问题