how can i restrict the access to only ajax requests?
ajax, express, javascript, node.js
Solution
With expressjs, you can respond only to xhr requests like this:
function handleOnlyXhr(req, res, next) {
if (!req.xhr) return next();
res.send({ "answer": "only is sent with xhr requests"});
}
(in your example, `routes.inicio.inicio` would use the pattern above by checking `req.xhr`)
Problem
i load inicio.jade with ajax req ``` $.ajax( { url:'/inicio', cache: false, type: 'GET', }).done(function(web) { $('#contenido_nav_principal').fadeOut(600,function() { $('#contenido_nav_principal').empty(); $('#contenido_nav_principal').html(web); $('#navegacion').animate({height:'600px'},200); $('#contenido_nav_principal').fadeIn(600); }); }); ``` from this address in the server ``` app.get('/inicio',routes.inicio.inicio); ``` the problem is that i can access to the page with http://www.mypage.com/inicio how can i restrict the access only to ajax requests and redirect to 404 error page if is not an ajax request