/** * 是不是Ajax請求 * @param request * @return */ public static boolean isAjax(ServletRequest request){ return "XMLHttpRequest".equalsIgnoreCase(((HttpServletRequest) request).getHeader("X-Requested-With")); }
ajax 請求會在請求頭部添加 X-Requested-With: XMLHttpRequestajax