0

I have a js-code:

$(document).on('click', '#form #submitForm', function(e){
    $('#form').submit();
    return false;
});


$(document).on('submit', '#form', function(e){
    // ajax request on submit form

    return false;
});

where #form is the id of form, #submitForm is the id of submit-button inside this form.

I use .on() because of fact that my form is dynamically generated by ajax requests on submit.

Some people with Google Chrome on Win7 complaints about this isn't working and by pressing #submitForm just redirect to "form action"-url occurs.

I have Google Chrome on Win7 and it's working perfectly.

Want do I missing or did wrong?

dima
  • 31
  • 1
  • 4

2 Answers2

0

When you submit a form, this will redirect to the url action. If you dont want to redirect, you have to create an ajax that "submit " the form

dacastro4
  • 363
  • 6
  • 17
0

What you need is to stop the default behaviour of form when submit button is pressed.

Change your code to this:

$(document).on('submit', '#form', function(e){
  // ajax request on submit form
  e.preventDefault();
  e.stopPropogation();
  return false;
});
Avnish Gaur
  • 489
  • 1
  • 4
  • 16
  • I think `return false;` in jquery means both `event.preventDefault()` and `event.stopPropagation()` – dima Oct 09 '14 at 22:35
  • well i am not really sure about the reliability of using return false.. see this question for example, http://stackoverflow.com/questions/18971284/event-preventdefault-vs-return-false-no-jquery – Avnish Gaur Oct 10 '14 at 07:14