【问题标题】:Post Request nonworking in firefox在Firefox中发布请求不工作
【发布时间】:2013-08-04 22:50:52
【问题描述】:
alert();  // this alert appears for Firefox too.
$('<form action="Order/Create" id="Formabc" method="POST">' +
            '<input type="hidden" name="WeightUnit" value="' + Units + '">' +
            '<input type="hidden" name="Premium" value="' + 'N/A' + '">' +
            '<input type="hidden" name="Cost" value="' + Cost + '">' +
            '</form>').submit();

我在 jQuery 模态模型提交上发布此表单。

它在 Chrome、Safari 和 IE 中有效,但在 Firefox 中无效..

【问题讨论】:

  • 你为什么不用$.ajax
  • 需要回一个完整的帖子...为什么它不起作用..有什么想法吗?
  • 您是否尝试在submit() 之前调用appendTo("body")
  • 您确定UnitsCost 已定义吗?你见过this answer吗?
  • "它可以在 Chrome、Firefox 和 IE 中运行。不能在 Firefox 中运行.."??

标签: jquery firefox cross-browser forms http-post


【解决方案1】:

正如 MasterAM 建议的那样,使用 ajax 会更好,但如果你不能出于某种原因,将该表单附加到 DOM 并随后触发它。

$('body').append('<form action="Order/Create" id="Formabc" method="POST">' +
            '<input type="hidden" name="WeightUnit" value="' + Units + '">' +
            '<input type="hidden" name="Premium" value="' + 'N/A' + '">' +
            '<input type="hidden" name="Cost" value="' + Cost + '">' +
            '</form>');


$('#Formabc').trigger('submit');

但是 ajax 仍然是一个更好的方法。

http://api.jquery.com/jQuery.ajax/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-14
    • 2018-01-08
    • 2017-12-23
    • 1970-01-01
    • 2023-03-22
    • 2018-10-06
    • 1970-01-01
    相关资源
    最近更新 更多