Revised middleware for ajax