Added error handling in case of AJAX failure