how use ajax to custom page template

i’m completely new to WordPress ajax .
i’m working on new custom template . there is a custom form which stores data on custom database .
for search section i need to use Ajax . then i found one way , that is create new template page which called json.php for example . it echoing the data in json formating .

How to create an ajax endpoint without js?

My question is fairly simple. I am working on a project that uses WordPress as a headless CMS(Kinda). I have created an ajax endpoint but it always returns 400.
Right now I have created a child theme to test these functionalities. Here’s the functions.php that I’m using.