Refactor AJAX request to be easier maintained. Add spinner during AJAX request.