-3

I have a submit event:

    $('#id').on('submit', function(e) {
    e.preventDefault();
    clicksCounter++;
    $.ajax({
        type: 'POST',
        data: {
            id: id,
            clickCounter: clicksCounter > 1
        },
        url: 'url',
        success: function(response) {
            if (response) {
                $('#modal').modal('hide');
            }
        }
    });
});

But somehow it's redirecting me to another page instead of going to the function. I thought that e.preventDefault() will help, but it didn't. Also tried location.reload(), but it didn't helped either.

Could someone explain me why? Thank you for your time

HELPME
  • 714
  • 14
  • 35

1 Answers1

2

I think that you are capturing the submit event on the wrong element. Instead of the submit button, it should be the ID of the form that is being submitted. E.g.

$('#myModalForm').on('submit', function(e) {
Jim Wright
  • 5,905
  • 1
  • 15
  • 34