Jquery Form.submit() on Chrome works but not in Firefox(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 中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!