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 中无


- Fetch API 如何获取响应体? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01