Jquery Form.submit()在Chrome上有效,但在Firefox上无效

时间:2022-06-19 20:30:44

I have the following function that collects data from a page, stuffs them all into the 'data' variable, appends it to a form then submits it.

我有下面的函数,从一个页面收集数据,把它们都塞到“data”变量中,把它附加到一个表单中,然后提交它。

 $(document).ready(function () {
$('#content-tab .submit').click(function () {
    var data = {champion: window.selectedChampion, runes: runes, masteries: masteries, items: items, skillingOrders: skillingOrders, chapters: chapters, title: $('#guide_title').val()};
            data = JSON.stringify(data); 
            $("<form method='post'>").append($('<input type="hidden" name="data" id="data">').val(data)).submit();
    });
});

There is a div on the page that triggers this when clicked on:

页面上有一个div,当点击时触发:

<div class='button pointer submit'>Submit</div>

All is well when tested in Chrome. The form submits then redirects to a page, just as planned. But while testing in Firefox (v. 5 and 6), clicking on the div does nothing. Nada. Zilch. I wonder what went wrong in Firefox? Any help would be highly appreciated. Thank you.

在Chrome上测试时一切都很好。表单按照计划提交然后重定向到页面。但是,在Firefox(5和6)中进行测试时,单击div则什么都不做。没有什么结果。无价值之物。我想知道Firefox出了什么问题?如有任何帮助,我们将不胜感激。谢谢你!

1 个解决方案

#1


39  

I would try adding the form to the DOM before submitting.

我将尝试在提交之前将表单添加到DOM。

$('#content-tab .submit').click(function() {

    var data = {
        champion: window.selectedChampion,
        runes: runes,
        masteries: masteries,
        items: items,
        skillingOrders: skillingOrders,
        chapters: chapters,
        title: $('#guide_title').val()
    };
    data = JSON.stringify(data);
    var $form = $("<form method='post'>").append($('<input type="hidden" name="data" id="data">').val(data));
    $form.appendTo("body").submit();

});

#1


39  

I would try adding the form to the DOM before submitting.

我将尝试在提交之前将表单添加到DOM。

$('#content-tab .submit').click(function() {

    var data = {
        champion: window.selectedChampion,
        runes: runes,
        masteries: masteries,
        items: items,
        skillingOrders: skillingOrders,
        chapters: chapters,
        title: $('#guide_title').val()
    };
    data = JSON.stringify(data);
    var $form = $("<form method='post'>").append($('<input type="hidden" name="data" id="data">').val(data));
    $form.appendTo("body").submit();

});