Ive seen another question answered about checking for ajax requests in express by looking in
我看到了另一个问题,即通过查找来检查ajax请求的快速查询
req.xhr
however this comes through as false when angular is requesting a template, surely this is ajax??
然而,当angle请求一个模板时,这是假的,这肯定是ajax吗?
Please help!
请帮助!
1 个解决方案
#1
0
req.xhr
is used to tell whether the request is ordinary browser request or it's an Ajax request. Most frameworks set the X-Requested-With
header to XMLHttpRequest
, You can check this in Express :
要求的事情。xhr用于判断请求是普通浏览器请求还是Ajax请求。大多数框架都将X-Requested-With header设置为XMLHttpRequest,您可以在Express中查看:
app.get('/path', function(req, res) {
var is_ajax = req.xhr; // this tells whether the request is ajax (true) or not (false)
...
});
#1
0
req.xhr
is used to tell whether the request is ordinary browser request or it's an Ajax request. Most frameworks set the X-Requested-With
header to XMLHttpRequest
, You can check this in Express :
要求的事情。xhr用于判断请求是普通浏览器请求还是Ajax请求。大多数框架都将X-Requested-With header设置为XMLHttpRequest,您可以在Express中查看:
app.get('/path', function(req, res) {
var is_ajax = req.xhr; // this tells whether the request is ajax (true) or not (false)
...
});