Adding security check to ajax function.