refined front-end code, particularly on error handling of ajax