Load More with AJAX

This syntax is not correct, please remove the outer square brackets. You cannot wrap compact inside an array, either use compact use put key/value pairs into an array.

Oh yeah, that fixed the error, thanks.

I still have the issue that when I press the more button, nothing happens. No errors at all.

These backticks shouldn’t be there either.

I think those are required for ES6, when i remove them it throws and error.

does it log the url to console when you click?

Yes, the URL is logged.

Do you get anything back from the ajax request if you log data after $.get?

I don’t get anything back from that. The .json is empty, there should be something there right?

But you can open the url in the browser?

Yeah the url does navigate to a pages yes.

What does that mean? If you open https://yourdomain.test/interviews.json you should not get a page but see some json data.

Yeah, no data show up at all. Very confused.

What do you get under that URL? an empty page? An error message?

If the page is empty, maybe the snippet doesn’t return anything. Test

html .= 'Some string here';

instead of the snippet to see if this returns anything.

Yeah, this doesn’t work. Its seems like that file is not compiling any PHP at all.

Hm, looks like $interviews is empty. Try to store dump($interviews) in the $html outside the loop.

<pre>Kirby\Cms\Pages Object
(
)
</pre>

Could you please post your current json controller again ( as code, not as screenshot)?

<?php

return function ($pages, $page) {
  
  $interviews = $pages->find('interviews')->children()->flip()->listed();
  $count = $interviews->count();

  $offset = intval(get('offset'));
  $limit  = intval(get('limit'));

  $interviews = $interviews->offset($offset)->limit($limit);

  $more = $count > $offset + $limit;

  return compact('offset', 'limit', 'interviews', 'more');
};

Ah, ok, since at this time (before the Javascript kicks in) these values are not set, $interviews will be empty. So this is normal behavior.

Once you call the URL via JS though, the request will change and these values will be set.

For testing, you can assign

  $offset = 0;// intval(get('offset'));
  $limit  = 2;// intval(get('limit'));

and your URL should then return something (undo this change again afterwards).

Yeah this works now.