# Ajax load more with filter

**URL:** <https://forum.getkirby.com/t/ajax-load-more-with-filter/7562>\
**Category:** Questions\
**Tags:** v2\
**Created:** [May 23, 2017, 2:05pm UTC](https://forum.getkirby.com/t/ajax-load-more-with-filter/7562 "2017-05-23T14:05:53Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 23, 2017, 5:29pm UTC](https://forum.getkirby.com/t/ajax-load-more-with-filter/7562/4 "2017-05-23T17:29:20Z")

</div>

You could, for example, send the post variable as a data attribute:

```auto
// controller
if(get('name') && get('name') != ''){
    $name = get('name');
 $results = $page->children()->not('people')->children()->sortBy('sort','asc');
} else {
  $name = '';
  $results = $page->children()->not('people')->children()->sortBy('name','desc');
}
//... rest of code
return compact('offset', 'limit', 'results', 'more', 'name');

```

In your template add a `data-name` attribute:

```auto
data-name="<?= $name ?>"

```

(where you have the other data attributes)

Then in your JS, get the value and pass it on in your get request (example from the tuturial, modify as needed):

```auto
$(function(){

  var element = $('.projects');
  var url = element.data('page') + '.json';
  var limit = parseInt(element.data('limit'));
  var offset = limit;
  // get the value from data-name attribute
  var name = element.data('name');

  $('.load-more').on('click', function(e) {
    // send the value with your Ajax request
    $.get(url, {limit: limit, offset: offset, firstname: firstname}, function(data) {

      if(data.more === false) {
        $('.load-more').hide();
      }

      element.children().last().after(data.html);

      offset += limit;

    });

  });

});

```

---

_[View the full topic](https://forum.getkirby.com/t/ajax-load-more-with-filter/7562)._
