铁轨涡轮
我正在尝试以编程为单位启动发布请求。
Turbo.visit('documents/path', { data: { 'turbo-method': 'post' } });
这是不起作用的,它会触发GET请求。
I am trying to initiate a post request programatically.
Turbo.visit('documents/path', { data: { 'turbo-method': 'post' } });
This is not working, it triggers a GET request.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
on docs 是通过js/turbo进行帖子的一种方法,但基于JS/Turbo,但在表单元素上:
«要编程提交元素,请调用
htmlformelement.requestsubmit()
方法并传递< input type type =“ submit”>或< button>
元素作为可选参数。»要纯粹以编程方式进行操作,我知道的唯一方法是将无涡轮增压的常规邮政请求发送到服务器,并通过Turbo Channel而不是Turbo Stream进行响应! 我的gem 这样做。取决于用例。
我认为,在大多数情况下,更清洁,更可取的方法是涡轮流,因此此问题可能是功能请求。但是您还必须通过邮寄发送CSRF令牌。
On docs is one way for doing a post by JS/Turbo, but based on a Form Element:
«To submit a element programmatically, invoke the
HTMLFormElement.requestSubmit()
method and pass an<input type="submit"> or <button>
element as an optional parameter.»To do it purely programmatically, the only way I know would be to send a regular post request, without any turbo, to the server, and respond via turbo channel, not turbo stream! My gem does this. Depends on the use case.
In my opinion, the cleaner and preferable way in most cases would be turbo-stream, so this issue could be a feature request. But you also have to send the CSRF token by post.