javaweb项目判断一个请求是否Ajax请求

boolean isAjax(HttpServletRequest request){
    return  (request.getHeader("X-Requested-With") != null  
    && "XMLHttpRequest".equals(request.getHeader("X-Requested-With").toString())) ;
}
// org.springframework.web.context.request.WebRequest;
public static boolean isAjaxRequest(WebRequest webRequest) {
    String requestedWith = webRequest.getHeader("X-Requested-With");
    return requestedWith != null ? "XMLHttpRequest".equals(requestedWith) : false;
}
发布了1184 篇原创文章 · 获赞 272 · 访问量 203万+

猜你喜欢

转载自blog.csdn.net/huangbaokang/article/details/104059686
今日推荐