Stack Exchange
Why firefox is saying "event is not defined" while it is working perfectly fine in chrome?
I am developing a ajax request which will login the user.The following script works fine in chrome but in firefox, it redirect to same page(basically not submitting the form) and  console says that "event is not defined".


$(document).ready(function() {
  $('#form2').submit(function() {
    $('#username_error').empty();
    $("#password_error").empty();
    var csrftoken = $("[name=csrfmiddlewaretoken]").val();

    var formdata = {
      'username': $('input[name=username]').val(),
      'password': $('input[name=loginpassword]').val(),
    };
    console.log("Formvalue is taken");

    $.ajax({
        type: 'POST',
        url: '/Submit/logging',
        data: formdata,
        dataType: 'json',
        encode: true,
        headers: {
          "X-CSRFToken": csrftoken
        },
      })

      .done(function(data) {
        console.log(data);
        if (!data.success) { //we will handle error
          if (data.password) {
            console.log(data.password);
            $('#password_error').text(data.password);
          }
          return false;

        } else {
          window.location = '/';
        }

      });
    event.preventDefault();
  });
});




Firefox does not assign current event to a global event like some other browsers do
You also want to move the preventDefault since any error happening later will break the script and allow the form to submit instead or as well as the Ajax 

ADD event to the function definition so it is passed:  


function(event) {

MOVE event.preventDefault(); to the top of your function 

Like this:
$('#form2').on("submit",function(event) {
  event.preventDefault();


I moved it to top but error still persists.As far as i see. firefox is not assigning event to click action of button

@Gagan Look at the suggested code in answer again. you need to pass event as an argument to the submit callback function. on("submit",function(event)  <-- this

@Gagan you only did half of what I suggested
