javascript - On submit function is not called -


at end of document have:

<script>     $("#submitevent").click(function() {         $("#eventform").submit();     });       $(document).ready(function() {       $('#eventform').submit(function() {         console.log("i on submit");      }); }); </script> 

now submitevent button not within form , reason having on .click event.

when button pressed form submit triggered correctly:

<form id="eventform" action="${contextpath}/dashboard/event/new"                         method="post"> 

now expect event fired when submit fired ignored reason. instead of console.log not surprisingly going use ajax, console.log not print event not triggered..

update, did suggested still nothing :-) :

$(document).ready(function() {      $("#submitevent").click(function() {         $("#eventform").submit();     });         $('#eventform').submit(function() {         console.log("i on submit");      });       }); 

if reason saying form submit handler isn't being called don't see output in console, remember submitting form tears down , replaces page. don't have time see log message before console gets cleared.


in comment, said:

hm, how can check if ajax called.

you can check setting breakpoint on console.log statement , seeing if breakpoint gets hit. or if want debug 1990's-style, use alert.

but note doing ajax within form submit handler, if form's result replace page, unreliable. (if form's result won't replace page, you're fine.) because ajax asynchronous, meaning submit handler start it, wouldn't have time finish before being cancelled teardown.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -