function inside ajax call