Skip to content

Instantly share code, notes, and snippets.

@klaemo
Created February 18, 2012 16:34
Show Gist options
  • Save klaemo/1860089 to your computer and use it in GitHub Desktop.
Save klaemo/1860089 to your computer and use it in GitHub Desktop.
express route conditional response
app.get('/users', function(req, res){
if (req.xhr) {
// respond with the each user in the collection
// passed to the "user" view
res.partial('user', users);
} else {
// respond with layout, and users page
// which internally does partial('user', users)
// along with other UI
res.render('users', { users: users });
}
});
@klaemo
Copy link
Author

klaemo commented Feb 18, 2012

yep, that works :) thank you for the quick response! coulda thought of that myself, though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment