问题描述
我使用下面的javascript函数来构造一个表单并将其提交给服务器。它在Chrome浏览器中运行正常,但不能在Firefox中运行。
function loadPage(url,projectName){
var jForm = $('< form>< / form>');
jForm.attr('action',url);
jForm.attr('method','post');
var jInput = $(< input>);
jInput.attr('name','curPrj');
jInput.attr('value',projectName);
jForm.append(jInput);
jForm.submit();
}
我从SE的旧文章中得到了一些建议,将表单追加到文档正文 document.body中。 appendChild(jForm)
但不幸的是,这也不适用于我。当我在表单提交之前使用 document.body.appendChild(jForm)
时,在调试控制台中出现以下错误。
TypeError:Node.appendChild的参数1没有实现接口节点。 @ http:// localhost:9000 / assets / javascripts / global.js
?请注意。
document.body.appendChild(jForm)
won因为 jForm
不是dom元素,所以它是一个jQuery对象,因此请在 jForm.submit(); $>之前添加以下脚本c $ c
$ p $ jForm.appendTo('body')
函数loadPage(url,projectName){
var jForm = $('< form>< / form>',{
action:url,
method:'post'
});
$(< input>,{
name:'curPrj',
value:projectName
})。appendTo(jForm);
jForm.appendTo('body')。submit();
}
I am using following javascript function to construct a form and submitting it to the server. It works fine in Chrome browser but not working in Firefox.
function loadPage(url, projectName){
var jForm = $('<form></form>');
jForm.attr('action', url);
jForm.attr('method', 'post');
var jInput = $("<input>");
jInput.attr('name', 'curPrj');
jInput.attr('value', projectName);
jForm.append(jInput);
jForm.submit();
}
I got some suggestion from SE's older post Mozilla form.submit() not working, to append the form to document body document.body.appendChild(jForm)
but unfortunately that didn't work for me either. I got following error in debug console when I used document.body.appendChild(jForm)
before form submit.
TypeError: Argument 1 of Node.appendChild does not implement interface Node. @ http://localhost:9000/assets/javascripts/global.js
Am I missing something here? Pls advise.
document.body.appendChild(jForm)
won't work because jForm
is not a dom element, it is a jQuery object so add the below script before jForm.submit();
jForm.appendTo('body')
function loadPage(url, projectName) {
var jForm = $('<form></form>', {
action: url,
method: 'post'
});
$("<input>", {
name: 'curPrj',
value: projectName
}).appendTo(jForm);
jForm.appendTo('body').submit();
}
这篇关于form.submit()在Firefox中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!