Improve AJAX error handling