Move ajax queueing logic into ajax.js