Added error handling to AJAX library.