Added error catching for the ajax request