使用Express检测NodeJS上的AJAX请求 [英] Detecting AJAX requests on NodeJS with Express
本文介绍了使用Express检测NodeJS上的AJAX请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
大多数框架设置 X请求 - 使用
头到 XMLHttpRequest
,其中Express有一个测试:
app.get('/ path',function(req,res){
var isAjaxRequest = req.xhr;
...
});
I'm using NodeJS with Express. How can I tell the difference between an ordinary browser request and an AJAX request? I know I could check the request headers but does Node/Exprsss expose this information?
解决方案
Most frameworks set the X-Requested-With
header to XMLHttpRequest
, for which Express has a test:
app.get('/path', function(req, res) {
var isAjaxRequest = req.xhr;
...
});
这篇关于使用Express检测NodeJS上的AJAX请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文