put ajax call into function