Java判断是否是Ajax异步请求

是否是 Ajax 请求:

ublic static boolean isAjaxRequest(HttpServletRequest request){
		
		String accept = request.getHeader("accept");
		String xRequestedWith = request.getHeader("X-Requested-With");
		
		// 如果是异步请求或是手机端,则直接返回信息
		return ((accept != null && accept.indexOf("application/json") != -1 
			|| (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1)
			));
	}

这里对参数 request 进行判断,

我们对

相关推荐