我有一个运行clojure的服务器,其中一个端点返回简单的json。
我从backbone.js集合到此端点进行回调。我已经在fetch()集合的返回xhr上放了一个done处理程序。但是,从未调用此完成的回调。我可以看到请求是200,并且正确的数据将发送到客户端。
代码在这里:
(defn getJson []
{:status 200
:headers {"Content-Type" "application/json"}
:body "[{id: 123, name: \"a2k jailed\"}, {id: 234, name: \"klmno won\"}]"
}
)
(defroutes main-routes*
(GET "/headlines" [] (getJson))
(route/resources "/")
(route/not-found "<h1>404 - Page not found</h1>"))
(def app (compojure.handler/site main-routes*))
(defn -main [port]
(def server (jetty/run-jetty #'app
{:port (Integer. port) :join? false})))
// backbone client side:
this.jsonCollection = new someClassExtendedFrombackboneCollection();
this.jsonCollection.fetch().done(function(jsons) {
console.log("jsons: " + jsons);
});
这里有什么不对的?