Placed ajax call into separate function