refactor from HTML form to XMLHttpRequest