view() makes your site display html and later on you force the page to output it as json instead ( with output() ). And therefore your browser thinks you want json and don't actually decode the site.
No, you need to use different functions or;
Add a parameter to your function and make an if/else statement
Check if it's an AJAX request if/else statement