Improved AJAX error handling