Rewritten ajax function.