标签:
req.xhr判断请求来自ajax还是普通请求;
若为ajax则是为true
这个属性是通过判断headers中的
x-requested-with的值来判断的
下面是来自ajax的请求:
1 host: ‘localhost:3000‘, 2 connection: ‘keep-alive‘, 3 accept: ‘*/*‘, 4 ‘if-none-match‘: ‘W/"b5-nK3C+n/aPR++6ICHo9ZKmQ"‘, 5 ‘user-agent‘: ‘Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.8 Safari/537.36‘, 6 ‘x-requested-with‘: ‘XMLHttpRequest‘, 7 referer: ‘http://localhost:3000/‘, 8 ‘accept-encoding‘: ‘gzip, deflate, sdch‘, 9 ‘accept-language‘: ‘zh-CN,zh;q=0.8‘, 10 cookie: ‘privatecloud_sid=s%3AXUaL1RJr1h2r6yb52djAwrK3TWaIL91V.iuM%2FJ5a0MgnJcBrBPBOqFVShhezZly%2BwxxZ2O2bIa%2Bg‘
下面是普通求求:
1 host: ‘localhost:3000‘, 2 connection: ‘keep-alive‘, 3 pragma: ‘no-cache‘, 4 ‘cache-control‘: ‘no-cache‘, 5 ‘upgrade-insecure-requests‘: ‘1‘, 6 ‘user-agent‘: ‘Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.8 Safari/537.36‘, 7 accept: ‘text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8‘, 8 ‘accept-encoding‘: ‘gzip, deflate, sdch‘, 9 ‘accept-language‘: ‘zh-CN,zh;q=0.8‘, 10 cookie: ‘privatecloud_sid=s%3AXUaL1RJr1h2r6yb52djAwrK3TWaIL91V.iuM%2FJ5a0MgnJcBrBPBOqFVShhezZly%2BwxxZ2O2bIa%2Bg‘
以上是通过req.headers打印出来的;
红色为相同属性,其他为不同属性;可以根据这些属性来做判断;
标签:
原文地址:http://www.cnblogs.com/suoking/p/5773969.html