Updated ajax library to handle errors as the server would