Jquery submit () not working with descriptor?

Why does it work:

    $("form[data-remote].edit_item").submit();

But is that not so?

    $("form[data-remote].edit_item").submit(function() {
             alert('goo')
    });
+3
source share
4 answers

In this case, you raise an event submit:

$("form[data-remote].edit_item").submit();

With this, you attach a handler to the event submit:

$("form[data-remote].edit_item").submit(function() {
   alert('goo');
});

In the second, you say “warning when an event occurs submit” ... you don’t say “hey, obey”, for this you still need to call .submit()or what is the shortcut for: .trigger("submit")... like this:

$("form[data-remote].edit_item").submit(function() {
   alert('goo');
}).submit();

... but at this moment, why not just notify separately? eg:

$("form[data-remote].edit_item").submit();
alert('goo');
+4
source

You are missing a semicolon after calling an alert.

+1
source

alert()?

$("form[data-remote].edit_item").submit(function(e) {
     e.preventDefault();
     alert('goo');
});
0

, .

0

Source: https://habr.com/ru/post/1777231/


All Articles