added error checking to ajax request