Fixed redirection bug by sending redirect in JSON.
Added code to handle success redirect in JSON response.