Adding error handling for ajax calls