rewrite ajax fucntion