javascript - Click function do not working after jquery validation added -
$(document).on('click', '#dodaj', function(e) { $("#addscrap").validate({ debug: true, rules: { job: { required: true, minlength: 3 }, keywords: { required: true, minlength: 5 } }, messages: { job: { required: "podaj nazwę analizy wykonania", minlength: jquery.validator.format("brakuje {0} znaków!") }, keywords: { required: "podaj słowa kluczowe analizy", minlength: jquery.validator.format("brakuje {0} znaków!") } }, submithandler: function(form) { var data = $("#addscrap").serialize(); $.ajax({ data: data, type: "post", datatype: "json", url: "views/addscrap.php", beforesend: function(data) { document.getelementbyid('alert').style.display = ''; $("#alert").text("dodawanie zadania..."); }, success: function(data) { if (data['error'] == 'exist') { document.getelementbyid('alerterror').style.display = ''; $('#alerterror').text('zadanie już istnieje'); document.getelementbyid('alert').style.display = 'none'; } else if (data['error'] == 'add') { document.getelementbyid('alerterror').style.display = 'none'; $('#alert').text('dodano zadanie'); document.getelementbyid('alert').style.display = ''; getlist(); } }, error: function(data) { document.getelementbyid('alerterror').style.display = ''; $("#alerterror").text("błąd, spróbuj ponownie"); document.getelementbyid('alert').style.display = 'none'; } }); } }); });
after when added jquery validation js, cannot click button #dodaj, there of course no errors in console. can please me resolve ? need add document on load function ?
this works if remove submithandler section, ajax run without doing validation on form.
<script> $( document ).ready(function() { $("#addscrap").validate({ rules: { job: { required: true, minlength: 3 }, keywords: { required: true, minlength: 5 } }, messages: { job: { required: "podaj nazwę analizy wykonania", minlength: jquery.validator.format("brakuje {0} znaków!") }, keywords: { required: "podaj słowa kluczowe analizy", minlength: jquery.validator.format("brakuje {0} znaków!") } }, submithandler: function(form) { var data = $("#addscrap").serialize(); $.ajax({ data: data, type: "post", datatype: "json", url: "views/addscrap.php", beforesend: function(data) { document.getelementbyid('alert').style.display = ''; $("#alert").text("dodawanie zadania..."); }, success: function(data){ if(data['error'] == 'exist') { document.getelementbyid('alerterror').style.display = ''; $('#alerterror').text('zadanie już istnieje'); document.getelementbyid('alert').style.display = 'none'; } else if(data['error'] == 'add') { document.getelementbyid('alerterror').style.display = 'none'; $('#alert').text('dodano zadanie'); document.getelementbyid('alert').style.display = ''; getlist(); } }, error: function(data) { document.getelementbyid('alerterror').style.display = ''; $("#alerterror").text("błąd, spróbuj ponownie"); document.getelementbyid('alert').style.display = 'none'; } }); } }); }); </script>
Comments
Post a Comment