【发布时间】:2021-11-20 15:30:26
【问题描述】:
<form
class="" id="form" hx-post="/add/" hx-swap="afterbegin" hx-target="#big_list" hx-trigger="submit">
<input type="text" name="langue1" >
<input type="text" name="langue2">
<div id="errors"></div>
<button type="submit">GO</button>
</form>
<div id="big_list">
.....
</div>
我在#big_list 中有一个很大的列表,我希望我的#form 在提交时只附加一行。
如何使用 htmx 处理错误并在 #errors 中显示消息?
【问题讨论】:
-
我的意思是:-如果我的请求成功,结果将放在
hx-target(这里:#big_list)-但是如果我的请求失败(300、400、HttpErrors ....)怎么办我把结果放在#errors but not in#big_list` 中?我就是这个意思。 -
对不起。我以前没有这样做过。偶然我读到这个:twitter.com/htmx_org/status/1443316447942348805
-
这些文档有帮助吗? htmx.org/docs/#requests 如果服务器出现错误响应(例如 404 或 501),htmx 将触发 htmx:responseError 事件,您可以处理该事件。如果发生连接错误,将触发 htmx:sendError 事件。
标签: htmx