Generalized the Ajax code a bit