Chrome上的Jquery Form.submit()可以运行但不适用于Firefox [英] Jquery Form.submit() on Chrome works but not in Firefox

查看:104
本文介绍了Chrome上的Jquery Form.submit()可以运行但不适用于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();
    });
});

点击时,页面上有一个div触发此信息:

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

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

在Chrome中测试时一切正常。然后提交的表单会按照计划重定向到页面。但是在Firefox中进行测试时(第5和第6版),点击div不会做任何事情。纳达。小人物。我想知道Firefox出了什么问题?任何帮助将受到高度赞赏。谢谢。

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.

推荐答案

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

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

$('#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();

});

这篇关于Chrome上的Jquery Form.submit()可以运行但不适用于Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆