generalized system to include $.ajax as a special case