Moved my ajax function to the right location