简体   繁体   中英

Jquery Form.submit() on Chrome works but not in 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();
    });
});

There is a div on the page that triggers this when clicked on:

<div class='button pointer submit'>Submit</div>

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.

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();

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM