我想從我的JavaScript(使用jquery post)發送json到compojure。我確信有一些事情很簡單,我做錯了。我的javascript文件(在它的全部)是這樣的:發送與jQuery的JSON對象,但在組合中收到零
$(document).ready(function() {
$.post("/", "foo", function(){});
});
我Clojure的服務器看起來像:
(ns spendy.routes
(:use compojure.core
spendy.core
ring.middleware.json-params
[hiccup.middleware :only (wrap-base-url)])
(:require [compojure.route :as route]
[compojure.handler :as handler]
[compojure.response :as response]
[clj-json.core :as json]))
(defroutes main-routes
(GET "/" [] (index-page))
(POST "/" [sent-object]
(println "got:" sent-object "from jquery")
(json/generate-string (respond-to-ajax (json/parse-string (if sent-object sent-object "")))))
(route/resources "/")
(route/not-found "Page not found"))
(def app
(-> (handler/site main-routes)
(wrap-base-url)))
當我加載頁面我希望得到
了:FOO從jquery
但是我得到了
了:從jQuery的
零發生了什麼事?