看公司代码没有理解
public static boolean isAjaxRequest(HttpServletRequest request) {
return "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
}
于是百度
if (request.getHeader("x-requested-with") != null
&& request.getHeader("x-requested-with").equalsIgnoreCase("XMLHttpRequest")) {
out.print("该请求是 AJAX 异步HTTP请求。");
}else{
out.print("该请求是传统的 同步HTTP请求。");
}
有什么用
我遇到的情况是,加上'X-Requested-With':'XMLHttpRequest'
返回数据是json
不加,返回数据是普通html文本
1、X-Requested-With 这个Http请求头有什么作用?
https://www.zhihu.com/question/30795602
2、HTTP之X-Requested-With分析和思考
http://blog.csdn.net/javajiawei/article/details/50563154
3、Ajax之X-Requested-With请求头
http://blog.51cto.com/woshixy/976695
4、Ajax 请求的http头信息特点 x-requested-with
http://rd-030.iteye.com/blog/2316105