Improved AJAX error handling.