Q:

In express.js is there a way to handle both ajax form submitions and browser post submits? 

I have a contact form on my site built with express.js (4.0).  I'm wondering how to handle the situation where my user has JavaScript Disabled.  
If the end of my routing function says:
res.render('contact.jade', {
  title: 'Thanks for reaching out!', 
  errors: errors,
  now: new Date().getFullYear()
});

Will this handle AJAX as well as a normal form submission?  Is there a better way to handle it? ( Does this hamper performance for either?) 

A:

You can use req.xhr when using express, which is set to true if the request has the X-Requested-With header set to XMLHttpRequest, which is done by most frameworks or can be done manually. 
Example:
if (req.xhr) {
    res.json(errors);
} else {
    res.render('contact.jade', {
        title: 'Thanks for reaching out!', 
        errors: errors,
        now: new Date().getFullYear()
    });
}

