How to submit form without page refresh

I’ve read the documentation, searched this forum and tried to learn from looking at the code of, as suggested, the Admin plugin but it’s way over my head.
If I’m correctly, the ‘trick’ in Grav to prevent a page refresh is to have Twig return data as JSON. Can this be done by modifying the Form plugin? I tried changing the template data.txt.twigto detect the request type like so:
— twig
{% if app.request.isXmlHttpRequest() %}
// code if ajax request
{% else %}
// code if not ajax request
{% endif %}

However, there seems to be more to it than that. Thanks in advance for suggestions and help on this.