K
K
Karen Mnatsakanyan2021-03-18 06:45:12
AJAX
Karen Mnatsakanyan, 2021-03-18 06:45:12

How to get number of ajax posts?

Good morning everybody!
How can I get the number of posts via ajax?

var filter_handler = function(page){   
    var filter = $('#filter');
    var data = filter.serialize();
    if( page ) data += '&paged=' + page;


    $.ajax({
        url:filter.attr('action'),
        data:data, // данные
        type:filter.attr('method'),
        beforeSend:function(xhr){
            filter.find('button').text('Загрузка...');
        },
        success:function(data){
            filter.find('button').text('Фильтровать');
            $('#response').parent().html(data);
        }
    });
    return false;
};

data.length doesn't work for some reason.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
v3shin, 2021-03-18
@v3shin

Give the response as json:

{
    "html": "...",
    "postsCount": 12345,
}

Well, if necessary, you can transfer page and postsPerPage there purely for reference.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question