简体   繁体   English

Chrome上的Jquery Form.submit()可以运行但不适用于Firefox

[英]Jquery Form.submit() on Chrome works but not in Firefox

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. 我有以下功能从页面收集数据,将它们全部填入“数据”变量,将其附加到表单然后提交它。

 $(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. 在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. 但是在Firefox中进行测试时(第5和第6版),点击div不会做任何事情。 Nada. 纳达。 Zilch. 小人物。 I wonder what went wrong in Firefox? 我想知道Firefox出了什么问题? Any help would be highly appreciated. 任何帮助将受到高度赞赏。 Thank you. 谢谢。

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();

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM