在jquery中提交表单 - 不在firefox上工作

时间:2022-12-06 21:14:24

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

尝试在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();

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.

只是为了添加...当我在提交下面的一行文本提醒时,我会在屏幕上显示警告框。看起来好像浏览器通过该代码很好(甚至可能提交表单)但我没有被重定向到表单操作地址。我也没有得到任何JS错误。

Once again, it fails only on Firefox and IE, Chrome does submission plus redirection fine.

再一次,它仅在Firefox和IE上失败,Chrome确实提交加重定向。

3 个解决方案

#1


3  

Try this code:

试试这段代码:

$(document).ready(function()
{
    /*
    *    IF IS APPEND, USE A ID OR CLASS
    */
    $('#X').append('<form id="myNewForm" class="myNewForm" method="post" action="">...</form>');
    $('#myNewForm').submit();

    //OR USE CLASS NAME
    $('form.myNewForm').submit();

    /*
    *    IF NOT APPEND, USE A ID OR CLASS
    */
    //USEA ID
    $('#myForm').submit();

    //USE A CLASS NAME
    $('form.my-form').submit();

    //USE A ELEMENT( ALL )
    $('form').submit();

});

Bye!

再见!

#2


0  

Frankly, I'm not sure if question on * 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

我有这个代码,基于Olaf的解决方案

    $('#basic-modal-content').append('<form id="acsform" 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>');
    $('#acsform').submit();

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)

这在IE,Firefox,Opera和Chrome上运行良好。但是今天,我们收到了一位客户的报告,说这个过程不适用于他的ipad。遗憾的是,我无法获得他在ipad上使用的浏览器的信息(我自己也没有自己检查的ipad),但似乎这段代码不起作用。日志中的最后一个操作是创建JSON对象的ajax操作,并且在接收到JSON之后触发上面的js。那是我的猜测。关于这个表单提交是否是ipad默认浏览器上的问题(无论该浏览器是什么),您对此有何了解吗?

#3


0  

Use native submit() with ID.

使用带ID的本机submit()。

$('<form/>', {name:"acsform", id:"acsform", method:"POST", action: JSONobject.formacsurl})
.append(
  $('<input/>', {type:"hidden", name:"PaReq", value: JSONobject.formpareq}),
  $('<input/>', {type:"hidden", name:"TermUrl", value: JSONobject.formtermUrl}),
  $('<input/>', {type:"hidden", name:"MD", value: JSONobject.formmd})
).appendTo(document.body)
$("form#acsform")[0].submit()

#1


3  

Try this code:

试试这段代码:

$(document).ready(function()
{
    /*
    *    IF IS APPEND, USE A ID OR CLASS
    */
    $('#X').append('<form id="myNewForm" class="myNewForm" method="post" action="">...</form>');
    $('#myNewForm').submit();

    //OR USE CLASS NAME
    $('form.myNewForm').submit();

    /*
    *    IF NOT APPEND, USE A ID OR CLASS
    */
    //USEA ID
    $('#myForm').submit();

    //USE A CLASS NAME
    $('form.my-form').submit();

    //USE A ELEMENT( ALL )
    $('form').submit();

});

Bye!

再见!

#2


0  

Frankly, I'm not sure if question on * 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

我有这个代码,基于Olaf的解决方案

    $('#basic-modal-content').append('<form id="acsform" 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>');
    $('#acsform').submit();

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)

这在IE,Firefox,Opera和Chrome上运行良好。但是今天,我们收到了一位客户的报告,说这个过程不适用于他的ipad。遗憾的是,我无法获得他在ipad上使用的浏览器的信息(我自己也没有自己检查的ipad),但似乎这段代码不起作用。日志中的最后一个操作是创建JSON对象的ajax操作,并且在接收到JSON之后触发上面的js。那是我的猜测。关于这个表单提交是否是ipad默认浏览器上的问题(无论该浏览器是什么),您对此有何了解吗?

#3


0  

Use native submit() with ID.

使用带ID的本机submit()。

$('<form/>', {name:"acsform", id:"acsform", method:"POST", action: JSONobject.formacsurl})
.append(
  $('<input/>', {type:"hidden", name:"PaReq", value: JSONobject.formpareq}),
  $('<input/>', {type:"hidden", name:"TermUrl", value: JSONobject.formtermUrl}),
  $('<input/>', {type:"hidden", name:"MD", value: JSONobject.formmd})
).appendTo(document.body)
$("form#acsform")[0].submit()