Refactor client-side JS code: HTML manipulation separated from Ajax calls