W
W
WebforSelf2021-09-23 13:16:32
AJAX
WebforSelf, 2021-09-23 13:16:32

Why does ajax return undefined?

There is a site - tyts

Below there is a button that loads the goods from page 2 with Ajax, the code is corny

var page = 1;
  $(document).on('click', '.show-more', function(e){
    e.preventDefault();
    page = page+1;
    
    $.ajax({
      type: 'GET',
      data:{'page':page},
      beforeSend: function(){
        $('.show-more').addClass('active');
      },
      success:function(data){
        content = $(data).find('.item_ajax');
        pagination = $(data).find('#pagination').html();
        console.log(content);
        console.log(pagination);
        setTimeout(function()
        {
          if(content.length>0)
          {
            $('#content').append(content);
            $('#pagination').html(pagination); 
            display($.totalStorage('display')); 
          }
          else
          {
            $('.show-more').html('<i class="fa fa-ban" aria-hidden="true"></i>Больше нет!');
            setTimeout(function()
            {
              $('.show-more').slideUp(350);
            }, 1600);
          }
          $('.show-more').removeClass('active');
        }, 700);
      }
    });
  });


Clicking on the button loads the next page.

Everything works fine on the standard template, but for some reason it returns.

e.fn.init [prevObject: e.fn.init(1), context: undefined, selector: '.item_ajax']

and
undefined

This is me logging
console.log(content);
        console.log(pagination);


The solution itself works, but some kind of conflict is created here, although #content , #pagination , .item_ajax are spelled correctly and in their places.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question