rewrite ajax.coffee and add state callbacks