Modify ajax method to be more generic.