Ajax request refactoring