php 判断是否为AJAX请求

2018-03-01T18:00:00
function isAjax($isPost = true)
{
    if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) {
        if ($isPost) {
            return (isset($_SERVER['REQUEST_METHOD']) && !strcasecmp($_SERVER['REQUEST_METHOD'], 'POST'));
        } else {
            return true;
        }
    } else {
        return false;
    }
}
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »