embedded function for ajax call