Answer the question
In order to leave comments, you need to log in
The ajax function to the form that is created by the template does not work. How to fix?
There are div .groups
<div class="col area">
<div class="row">
<div class="col-5 groups table-responsive" id="groups">
</div>
<div class="col-6 posts">
</div>
</div>
</div>
<script id="entry-template" type="text/x-handlebars-template">
<form action="function.php" method="get" id="btnposts">
{{#each response}}
<label><input type="checkbox" name={{screen_name}} value={{gid}}><img src={{photo}} alt={{screen_name}}> {{name}}</label><br>
{{/each}}
<input type="submit" value="Посты" class="btn btn-outline-success" onclick=f()>
</form>
</script>
$(document).ready(function(){
$( "#btnposts" ).submit(function( event ) {
event.preventDefault();
$.ajax({
type: 'get',
url: 'function.php',
data: {'getPosts':'yes'},
contentType: false,
cache: false,
proccessData: true,
success: function(result) {
alert(result);
}
})
});
})
Answer the question
In order to leave comments, you need to log in
Do it in this way:
$(document).on('submit', '#btnposts', functions() { /*код формы*/})
You have already been answered correctly, I will add - read about event delegation in JS in order to better understand what is happening
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question