ajax request refactoring