如何检查节点中的XHR

时间:2014-10-07 09:02:11

标签: node.js angularjs express

我已经看到另一个问题,通过查看

来检查快递中的ajax请求
    req.xhr

然而,当angular请求模板时,这会出现错误,当然这是ajax ??

请帮忙!

1 个答案:

答案 0 :(得分:0)

req.xhr用于判断请求是普通浏览器请求还是Ajax请求。大多数框架将X-Requested-With标头设置为XMLHttpRequest,您可以在Express中查看:

app.get('/path', function(req, res) {
  var is_ajax = req.xhr;    // this tells whether the request is ajax (true) or not (false)
  ...
});
相关问题