php - Ajax link after infinite scroll not working -


i'm making bookshop more 100 books. through search function i'm loading 10 books @ same time. when user scrolls down infinite scroll function loads 10 new books (with ajax).

next every book title buy link. ajax link adding book in shopping cart.

<a href="/books/buy" onclick="return false"><i class="glyphicon glyphicon-circle-arrow-right" id="book<?php echo $bookid;?>"></i></a>  <script type="text/javascript"> $(document).on("click","#book<?php echo $bookid;?>",function(){             $.ajax({url: "books/buy/<?php echo $bookid;?>",                          type:'post',                })   }); </script> 

the ajax link first books working good. link books loaded infinite scroll not working.

while trying find solution noticed when don't use bookid, icons have same id, ajax link working don't know book selected. , if don't use invite scroll works have load many books @ once.

i think there better way listeners.

<a href="/books/buy/<?php echo $bookid;?>" id="book-link">     <i class="glyphicon glyphicon-circle-arrow-right></i> </a>  <script type="text/javascript">     $(document).on("click","#book-link", function(e) {         e.preventdefault();         $.ajax({              url: $(this).attr('href'),              type:'post',         })     }); </script> 

you need load script part once, when load page.

i hope helps.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -