General refactor PHP to HTML plus ajax calls