jquery's form submit not working in IE

前端 未结 4 1857
攒了一身酷
攒了一身酷 2020-12-06 20:18

What we are trying to do here is that we have a form with an id of upgrade_form. We also have a form called \'paypal_submit\' form. This form is blank. \'upgrade_form\' has

相关标签:
4条回答
  • 2020-12-06 20:45

    If you haven't already, you could try stepping through it using the built-in IE JavaScript debugger (built in since IE8, or downloadable pre IE8)?

    Many people use firebug - because it's awesome :) but many people don't realise the hidden talent of the built in debugger in IE 8.

    It's got the same fundemental features as any other script debugger, but here is a guide for the specific features if you haven't come across it before:

    0 讨论(0)
  • 2020-12-06 20:48

    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.

    0 讨论(0)
  • 2020-12-06 20:48

    Changing the way you've formatted the .each() method seems to do the trick...

    $('form#paypal-form').submit( function(e) {
      e.preventDefault();
      var parameters = $('form#upgrade_form').serializeArray();
      $(parameters).each(function(i,param){
        $('<input />').attr('type', 'hidden')
        .attr('name', param.name)
        .attr('value', param.value)
        .appendTo('form#paypal-form');
      });     
    });
    
    0 讨论(0)
  • 2020-12-06 21:06

    Would a try...catch statement inside the each() reveal the error ?

    0 讨论(0)
提交回复
热议问题