我有一个使用htmx的表单,试图将第一个输入的输入值发送到Gin服务器
<form hx-post="/addToDo" hx-ext="json-enc" hx-trigger="submit" hx-target="#todos" hx-swap="outerHTML">
<input type="text" placeholder="todo" name="todo" />
<input type="submit" />
</form>
<ol id="todos"></ol>
Gin服务器
r.POST("/addToDo", func(c *gin.Context) {
fmt.Println(c.Request.Body)
// ^this prints "&{0xc0000b2000 <nil> <nil> false true {0 0} false false false 0xeaee20}"
jsonData, err := ioutil.ReadAll(c.Request.Body)
if err != nil {
fmt.Println("something went wrong here boys")
return
}
fmt.Println(jsonData)
// ^this prints "[116 111 100 111 61 104 101 108 108 111]"
})
我想过让POST请求URL包含输入值作为参数,但我相当肯定在请求正文中有一种方法可以做到这一点,我只是遗漏了一些东西.如何获取请求正文或查询"TODO"输入?