javascript - 如何使用 javascript 自动提交表单(onevent)?

标签 javascript html forms

我希望能够在事件中自动提交表单(通用表单,用于用户跟踪)。

例如,创建一个 POST 到 http://www.example.com/index.php?option=track&variable=variable application/x-www-form-urlencoded 之类的东西

username=usernamestring
otherdata=otherdata_string
otherdata2=otherdata string 2

不过,实际的字符串将被预格式化,因为它就像一个“ping”。 需要提交一个事件,使用外部js ( http://example.com/scripts/js.js )

我该怎么办?这越来越烦人了。

更新:我想我并没有真正说清楚;我有一个不应该显示在页面上的预制表格;它需要提交一个事件。页面上不存在表单字段;我所做的只是链接到页面上的脚本并执行 onLoad。

POST uri:http://www.example.com/index.php?option=track&variable=variable 上面的参数(option=track 和 variable=variable)不是表单详细信息(postdata)。

内容类型为 application/x-www-form-urlencoded ,并具有以下键/值。

username=usernamestring
otherdata=otherdata_string
otherdata2=otherdata string 2 (when encoded, the spaces get turned to %20's.)

我需要一个在运行时提交这个的脚本。

最佳答案

您必须获取表单对象并调用HTMLFormObject 提供的submit(); 函数。

document.getElementById('myForm').submit();

关于javascript - 如何使用 javascript 自动提交表单(onevent)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8870827/

相关文章:

javascript - Google map API - results.geometry.location[0] 返回 null

javascript - Python Selenium : Click on a radio button

javascript - 点击按钮并用文本填充后在两个文本区域中添加新行

JavaScript 确认取消在 Laravel 表单上不起作用

asp.net - jQuery POST 不改变 IsPostback 变量

javascript - 导航属性不会刷新

html - 改变 body 不是 HTML/CSS 标准吗?

javascript - 拒绝执行来自 'file_name.php' 的脚本,因为它的 MIME 类型 ('text/html' ) 不可执行,并且启用了严格的 MIME 类型检查

html - 让 IE 像其他浏览器一样显示的技巧

javascript - Angular JS 与快速联系表单返回 404