如何在HTML中发出POST请求而无需打开新标签

时间:2018-12-03 04:17:30

标签: html

我正在寻找一种通过按下按钮来执行HTML中的POST请求的方法,但是有问题。我希望它不打开要发布到的URL的新窗口,也不打开要发布到的URL。有任何想法吗?我有一些代码,但是只是发布到URL的按钮

代码:

 <form action="http://google.ca" method="post" target="_blank">
  <div>
    <button>post</button>
  </div>
 </form>

此外,我刚开始使用HTML,对此一无所知。谢谢。

3 个答案:

答案 0 :(得分:1)

-1

答案 1 :(得分:0)

删除此属性:

ValueError: Can't cast from structure to non-structure, except if the structure only has a single field.

这是打开新标签页的属性,而target="_blank" 则定位当前标签页/窗口。将整个代码更改为此:

_self

答案 2 :(得分:0)

从表单中删除target="_blank"。默认设置是在同一页面上提交:

 <form action="http://google.ca" method="post">
  <div>
    <button>post</button>
  </div>
 </form>