私は(jquery postを使用して)javascriptからcompojureにjsonを送信しようとしています。私が間違っているという単純なことがあると確信しています。私のjavascriptファイル(全体)は次のようになります:
$(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)))
ページをロードすると、取得する予定です
取得:jqueryからfoo
代わりに私は得る
取得:jqueryからnil
何が起こっている?