JQuery .submit 方法在 Firefox 中不起作用
在我的 javascript 文件中,我有一个如下代码片段:
$('<form action="process.php" method="POST">' +
'<input type="hidden" name="amp" value="' + calcJSON.totalAmpDay + '">' +
'<input type="hidden" name="watt" value="' + calcJSON.maxWattRate + '">' +
'<input type="hidden" name="dc_volt" value="' + document.number.dc_volt.value + '">' +
'</form>').submit();
上面的代码包含在函数定义中。当我单击按钮时,会调用该函数,然后浏览器应重定向到包含一些 POST 数据的“process.php”页面。 但只有 Chrome 会将我重定向到新页面,而 Firefox 不会。
如何解决这个问题?
In my javascript file, I have a code snippet like:
$('<form action="process.php" method="POST">' +
'<input type="hidden" name="amp" value="' + calcJSON.totalAmpDay + '">' +
'<input type="hidden" name="watt" value="' + calcJSON.maxWattRate + '">' +
'<input type="hidden" name="dc_volt" value="' + document.number.dc_volt.value + '">' +
'</form>').submit();
The above code is included within a function definition. When I click a button, that function is called and then the browser should be redirected to "process.php" page with some POST data.
But only Chrome redirects me to a new page but Firefox wont.
How can this issue be resolved ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
大约一周前也遇到过同样的问题。我需要纠正,但我相信在 Firefox 中,表单必须先添加到 DOM 中,然后才能提交。我通过将 CSS 设置为“display: none”解决了这个问题,并在运行提交方法之前将表单添加到页面上的任意元素。
Had this same problem about a week ago. I stand to be corrected but I believe in Firefox the form has to be added to the DOM before it can be submitted. I solved this by setting the CSS to "display: none" and added the form to an arbitrary element on the page before running the submit method.
提醒(或 console.log) -
在提交表单之前 字符串。该字符串看起来像有效的表单定义吗?
Alert (or console.log) the -
string before submitting the form. Does the string look like a valid form definition?
作为一个好的建议,使用 firebug 进行调试以查看错误并将其附加到讨论中以查看实际发生的情况。这有助于查明问题并提供帮助。请参阅:firebug 断点
Just as a suggestion for good, debug it with firebug to see the error and append it to discussion to see what is actually happening.That helps to pinpoint the problem and help. See:firebug breakpoint