Ajax in Kirby Controller

hello all you wonderful people!

so i have just a quick (hopefully) question about implementing AJAX into my kirby site, is it handle AJAX requests through a kirby controller? and if so, how exactly could that be accomplished

i was thinking it could return data through json or the likes, is this doable at all? i’ve seen a few posts on here that showed doing it in a template, and i believe that the ajax request is just returning the html content from the page when it’s an ajax request, but that doesn’t seem entirely too ideal for me and i’d rather keep it separate from everything else, and if i can indeed use JSON with it that’d be even more beautiful

thanks you all <3 everyone on this forum is so helpful and i cannot be more appreciative of it!

edit: to clarify, i’ve been using post requests onto the same page and handling that in the kirby controller, but the page refreshing each time isnt ideal for me, i would just like the same functionality but instead handled by ajax <3

i want to pull information from a structure field on the page’s blueprint based on the value that’s been set in the user’s row in MySQL

Check out this post for using json and to use your ajax script outside of a template (though not in a controller) Where can I save my PHP-Files for AJAX?

i think i did see this, is there no way to use this in a controller?

something akin to what i’m already using right now:

if( (r::is('post') and get('pwSubmit')) and ( $site->user() ) ) {}

if not, then that’s alright but it would be nice <3