Javascript form.submit() not working in Firefox

ぃ、小莉子 提交于 2019-12-04 00:50:33

Firefox expects that, when you submit a form, you have at least a submit button available, meaning there should be something like:

<button type="submit">Click me</button>

or:

<input type="submit" value="Click me" />

When you use the first one in your code, it will not work (because you strip out all buttons before submitting the form). When you use the second option, it will work, also in Firefox. As you can see in this fiddle: http://jsfiddle.net/q9Dzc/1/

For anyone having an issue with making the Firefox submit with the page location changing / reloading afterwards, you need to put your redirect code in the $.post callback:

$(".form").submit(function(e){
    e.preventDefault();
    $.post("submit.php", {data: textData}, function(){
        history.go(-1);
    });
    return false;
});

I had similar behaviour, when form.submit() didn't work on Firefox, but worked on other browsers. Just make sure that all the buttons within form contain type="button".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!