0

I'm building a library to save watched series and I'm struggling with some sort of incompatibility with my JQuery script. It works as intended in Chrome and Edge but not in Firefox. The reason of this script is to populate a div with content.

    <script>
  jQuery(document).on('submit', '.seasons_form', function(e){  
  event.preventDefault();

$.ajax({

type: "POST",
url: $(this).attr("action"),
data: $(this).serialize(),

success:function(data){
;


    document.getElementById("chapters_container").innerHTML = (data);

},
error:function(xhr,exception)
{

}
})
e.preventDefault();
  });

</script>

In Firefox it redirects me to the function I'm calling instead of populating the div. I have read several similar problems here but I can not find the solution.

Is anyone able to help? Thanks in advance.

2
  • 1
    You should use e.preventDefault() not event.preventDefault() because you named your event argument "e" Commented Nov 7, 2017 at 14:13
  • I'm hoping the error:function() isn't actually blank in the code you're using. Letting errors fall through the cracks like this is really bad practice. At a minimum, you should be doing an alert out to the user to let them know something didn't work as expected. Commented Nov 7, 2017 at 14:15

1 Answer 1

1

You need to pass the event variable with your function in FireFox, such as:

jQuery(document).on('submit', '.seasons_form', function(event) {}

It is a global variable in IE and Chrome etc. but not in FF. As a result you need to pass it explicitly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.