1
考虑下面的Compojure路由:总结PARAMS(cljs-AJAX +的Compojure)
(defroutes main-routes
(POST "/something" r {:body (prn-str (:params r))}))
(def handler
(-> main-routes
(wrap-params)))
当测试这与curl
我得到了想要的结果:
curl -d "a=b" localhost:3000/something
{"a" "b"}
岗位参数通过compojure阅读并包装到params-map中。
然而,这并不由cljs-Ajax库发起一个Ajax请求工作:
(POST "/something" {:handler #(js/alert %)
:params {"a" "b"}})
它告诫 “{}
”。当改变代码使用GET时,它可以工作。我猜这是由于浏览器将主体作为输入流而不是纯文本发送的原因。但我不确定,我不知道如何解决这个问题。
也许你可以尝试在cljs-ajax调用中设置'{...:format:raw ...}'? – jsonmurphy
你检查过使用cljs-ajax时,是否发送了'PUT'请求而不是'POST'?只是说。 – Marcs