moved ajax function into controllers