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


基础教程推荐
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01