refactor ajax spinner code