1

<script type="text/javascript">
 $(document).ready(function() {
var page = 0;
 $(window).scroll(function () {

        if ($(document).height()-$(document).height()*0.2  <= $(window).scrollTop() + $(window).height()) {
            
                   $.ajax({
                    type: "POST",
                    url: "/",
                    dataType: "json",
                    data: { 'page' : page, 'csrfmiddlewaretoken': '{{csrf_token}}'},
                    success: function(data) {
                        obj1 = JSON.parse(data.fulldata);    
                        var newHTML = '<a href = "" >somecode</a>';
      $(".newdata").append(newHTML);
     },
     error: function(data) {
                     // alert("error")
              }
                });
               }
        }
    });
</script>

i have readed this link for dynamically added elements, that we must bind the function to one of it's parents ...but no success

i am not pasting the entire code here. suppose code is correct and working fine. only when i am clicking the loaded element its not working..

Thanks in advance

full code

Community
  • 1
  • 1
Harish
  • 425
  • 7
  • 22
  • 1
    Doing `$(".newdata").on("click", '.add-to-cart', function()...)` didnt worked? – Karl-André Gagnon Oct 28 '15 at 18:18
  • 1
    If you are adding an element after the page is already loaded you can't bind events in ` $(document).ready`. You have to add the binding after the code that created the new element runs. – SunKnight0 Oct 28 '15 at 18:21
  • 1
    You making 2x JSON parsing. First time you specifying parsing in AJAX setup and second after data are received. – meshosk Oct 28 '15 at 18:24
  • karl-andre gagnon. thanks now its working .. and thanks all for ur suggestion. – Harish Oct 28 '15 at 18:38

0 Answers0