trinth
trinth

Reputation: 6047

How to submit a form via anchor using jQuery in IE9

I have something to the effect of :

<a href="#" >click me</a>

And:

$(document).ready(function() {
  $('a').click(function() {
    $('<form action="/" method="post"></form>').submit();
    return false;
  }
}

The expected result is that clicking the anchor will submit the form and redirect the page. This works in Chrome and Firefox. In Internet Explorer 9, the browser just follows the link to #. Any solutions?

Upvotes: 1

Views: 925

Answers (2)

Kunal Ranglani
Kunal Ranglani

Reputation: 408

Try this

    $('a').click(function() { 
        var form = '<form action="/" method="post"></form>';
        $('body').append(form);
        $('form:last').submit();
    } );

Upvotes: 3

Kevin B
Kevin B

Reputation: 95048

I would try appending the form to the body first. However, why do you need a form at all?

$(document).ready(function() {
  $('a').click(function() {
    $.post("/");
    return false;
  }
});

Upvotes: 0

Related Questions