PHP check whether Incoming Request is JSON type

前端 未结 6 1092
轻奢々
轻奢々 2020-12-20 14:57

Is there anyway to check whether an incoming request is of AJAX JSON type?

I tried

if(($_SERVER[\'REQUEST_METHOD\']==\'JSON\'))
{
}

6条回答
  •  -上瘾入骨i
    2020-12-20 15:53

    You can check the X-Requested-With header, some libraries, like jQuery set it to "XMLHttpRequest".

    $isAjaxRequest = $_SERVER['X_REQUESTED_WITH'] == 'XMLHttpRequest';
    

提交回复
热议问题