0

I am using jquery to post a form. Works fine on all browsers apart from IE, IE does not seem to be picking up the "prevent default" as the browser is directing to "beta.php". Here is my code

    $(document).ready(function(){   
        $("#betaform").submit(function(e){
            event.preventDefault();
            $.ajax({
                url: "beta.php",
                type: "POST",
                data: $(this).serialize(),
                success: function(data){
                    content = "<H2>Thank you, data received</H2>";
                    $("#betaform").empty().append(content);
                }

            });
        });

     });
user813813
  • 323
  • 1
  • 8
  • 28

3 Answers3

2

Instead of using event.preventDefault();, use e.preventDefault().

You've passed e through in the function:

$("#betaform").submit(function(e){
                               ^ here

So either change e to event or event to e.

Zach has also stated that return false; could be included too.

Make sure if you do include return false, it goes at the bottom of the function.

$(document).ready(function(){   
    $("#betaform").submit(function(e){
        e.preventDefault();
        $.ajax({
            url: "beta.php",
            type: "POST",
            data: $(this).serialize(),
            success: function(data){
                content = "<H2>Thank you, data received</H2>";
                $("#betaform").empty().append(content);
            }

        });
      return false; // here
    });

 });
Albzi
  • 15,431
  • 6
  • 46
  • 63
0

We use this function for cross-browser support because event.preventDefault() doesn't exist in earlier version of IE.

function PreventDefault(event) {
    event.preventDefault ? event.preventDefault() : event.returnValue = false;
}
Joce Pedno
  • 334
  • 1
  • 7
0

The JavaScript submit event does not bubble in Internet Explorer. However, scripts that rely on event delegation with the submit event will work consistently across browsers as of jQuery 1.4, which has normalized the event's behavior.

Forms and their child elements should not use input names or ids that conflict with properties of a form, such as submit, length, or method. Name conflicts can cause confusing failures. For a complete list of rules and to check your markup for these problems

from jQuery API

Go and check all tags inside form and check for attributes having value (submit, length, or method) and rename attributes on something like:

<input type="submit" id="submit" name="submit" />

into

<input type="submit" id="submision" name="valid" />
SilentTremor
  • 4,747
  • 2
  • 21
  • 34