jQuery form submit() is not working in IE6?

后端 未结 8 1795
忘掉有多难
忘掉有多难 2020-12-03 01:14

I want to submit a with using jquery as below;

$(\"#formid\").submit();

Its working perfect in all browsers except IE6.

How to mak

8条回答
  •  清歌不尽
    2020-12-03 01:53

    I've recently had a similar issue, where I was creating a "pseudo-form" within an ASP.NET server form (so I couldn't use another form tag), which I wanted to post to another domain without needing to write server-side code to do the remote post. Easy answer - create a form on the fly and submit it. Works in good browsers...

    After some trials and tribulations, I realised that IE won't work as expected (what a surprise) unless the form that is being submitted has been added to DOM. So, this was my solution. I hope it helps some of you. Please be aware, all of my inputs and my submit were in the same container. ".post-to" is a hidden input with the URL.

    $(".post-form").click(function(ev) {
    
        var postto = $(this).siblings(".post-to").val();    
        var form = document.createElement("form")
        $(form).attr("id", "reg-form").attr("name", "reg-form").attr("action", postto).attr("method", "post").attr("enctype", "multipart/form-data");
    
        $(this).siblings("input:text").each(function() {
            $(form).append($(this).clone());
        });
    
        document.body.appendChild(form);
        form.submit();
        document.body.removeChild(form);
    
        return false;
    });
    

    Eventually, it works a treat.

提交回复
热议问题