moved ajax out, added global var