在 jquery 中提交表单 - 不适用于 firefox
尝试在 JavaScript 调用中创建并提交表单。此代码在 Chrome 上运行良好,但在 Firefox 和 IE 上不起作用。我首先从 Ajax 调用 (JSON) 获取值,然后将其作为表单提交
$('<form name="acsform" action="' + JSONobject.formacsurl +'" method="POST">' +
'<input type="hidden" name="PaReq" value="' +JSONobject.formpareq + '">' +
'<input type="hidden" name="TermUrl" value="'+ JSONobject.formtermUrl +'">' +
'<input type="hidden" name="MD" value="'+ JSONobject.formmd +'">' +
'</form>').submit();
有什么想法吗?
只是添加...当我在该提交下方的一行中提醒某些文本时,我会在屏幕上看到警告框。浏览器似乎可以很好地浏览该代码(甚至可能提交表单),但我没有被重定向到表单 action
地址。我也没有收到任何 JS 错误。
再一次,它仅在 Firefox 和 IE 上失败,Chrome 可以正常提交和重定向。
Trying to create and submit form within a javascript call. This code works fine on Chrome but doesn't on Firefox and IE. I first get values from Ajax call (JSON) and then submit it as a form
$('<form name="acsform" action="' + JSONobject.formacsurl +'" method="POST">' +
'<input type="hidden" name="PaReq" value="' +JSONobject.formpareq + '">' +
'<input type="hidden" name="TermUrl" value="'+ JSONobject.formtermUrl +'">' +
'<input type="hidden" name="MD" value="'+ JSONobject.formmd +'">' +
'</form>').submit();
Any ideas?
Just to add... when I alert some text a line below that submission, I get the alert box on the screen. It may seem like browser goes through that code fine (perhaps even submits the form) but I'm not being redirected to forms action
address. I don't get any JS errors either.
Once again, it fails only on Firefox and IE, Chrome does submission plus redirection fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个代码:
再见!
Try this code:
Bye!
坦率地说,我不确定 stackoverflow 上的问题是否可以通过评论来解决,以及是否可以通过回答自己的问题来解决,但我真的不想创建一个新问题并复制这个问题的内容,
我有这段代码,基于 Olaf 的解决方案,
这在 IE、Firefox、Opera 和 Chrome 上运行良好。但今天,我们收到一位客户的报告,称该过程无法在他的 iPad 上运行。不幸的是,我无法获取他在该 ipad 上使用的到底是什么浏览器的信息(而且我自己没有 ipad 可以检查),但似乎这段代码不起作用。日志中的最后一个操作是创建 JSON 对象的 ajax 操作,上面的 js 在收到该 JSON 后被触发。那是我的猜测。
您是否清楚地知道此表单提交在 ipad 默认浏览器(无论该浏览器是什么)上存在问题?
Frankly, I'm not sure if question on stackoverflow can be bumped by commenting it and if it's allowed to bump by answering your own question, but don't really want to create a new one and copy content of this one
I have this code, based on a solution from Olaf
This worked all fine on IEs, Firefox, Opera and Chrome. But today, we got a report from a customer, that the process didn't work from his ipad. I unfortunately cannot get information what browser exactly is he using on that ipad (and I don't have an ipad myself to check) but it seems that this piece of code didn't work. Last operation in the logs is ajax operation that creates JSON object and the js above is fired after receiving that JSON. It's my guess then.
Do you know anything from top of your head in regard to this form submission being a problem on ipad default browser (whatever that browser is)
使用带 ID 的原生 Submit()。
Use native submit() with ID.