Adding JSON response and AJAX customization. Added CSRF support too.