我希望能够在事件中自动提交表单(通用表单,用于用户跟踪)。
例如,创建一个 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/