gpt4 book ai didi

clojure - Compojure 绑定(bind)来自 URL 的 HTTP 请求参数,而不是来自 POST 表单

转载 作者:行者123 更新时间:2023-12-03 23:01:24 24 4
gpt4 key购买 nike

Compojure 不绑定(bind) POST 表单中的字段。这是我的路线定义:

(defroutes main-routes
(POST "/query" {params :params}
(debug (str "|" params "|"))
"OK...")
)

当我发布一个包含字段的表单时,我得到 |{}|,即没有参数。顺便说一句,当我去 http://localhost/query?param1=value1 , params 不为空,并且值会打印在服务器控制台上。

表单字段是否有另一个绑定(bind)?

最佳答案

确保您有带有 name="zzz"属性的输入字段,但不仅仅是 id="zzz"。

html 表单收集所有输入并使用 name 属性发布它们

my_post.html

<form action="my_post_route" method="post">
<label for="id">id</label> <input type="text" name="id" id="id" />
<label for="aaaa">aaa</label> <input type="text" name="aaa" id="aaa" />
<button type="submit">send</button>
</form>

my_routes.clj
(defroutes default-handler
;,,,,
(POST "/my_post_route" {params :params}
(str "POST id=" (params "id") " params=" params))
;,,,,

产生类似的 react

id=21 params={"aaa" "aoeu", "id" "21"}

关于clojure - Compojure 绑定(bind)来自 URL 的 HTTP 请求参数,而不是来自 POST 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3862535/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com