News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

David Stockton's Blog:
Changing ErrorController to work with AJAX
August 12, 2011 @ 08:58:06

David Stockton has a new tutorial posted to his blog - a technique he's found useful in his Zend Framework application to make the ErrorController work with Ajax calls to reduce the message you get back to just a JSON response.

If you've ever built a Zend Framework MVC app which makes AJAX calls, you may have noticed that if an error occurs, you'll get a chunk of JSON followed by the HTML for the error page. If you've built a layout, you'll get all of that back to. This is fine if your users hit the page in the browser but it can cause problems with your JavaScript being able to correctly decode your JSON.

The fix is pretty simple, though, and only requires that you add the error handling action to the Ajax context to force it to drop the layout and any other HTML that might come along with the view. He includes a bit more code to have the error handler include the exceptions and pass them out to be included in the JSON response.

0 comments voice your opinion now!
zendframework error handler controller ajax response exception


blog comments powered by Disqus

Similar Posts

NetTuts.com: How to Upload Files with CodeIgniter and AJAX

Liip Blog: Why a Project Switched from Google Search Appliance to Zend_Lucene

Anis Ahmad's Blog: Join Problems with Zend_Paginator and Zend_Db_Select objects

Joshua Eichorn's Blog: Understanding AJAX excerpt available at computerworld.com

Fabien Potencier's Blog: PHP Serialization, Stack Traces, and Exceptions


Community Events





Don't see your event here?
Let us know!


introduction release laravel framework opinion composer podcast artisanfiles series interview symfony list tool security language version voicesoftheelephpant library conference community

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework