Handling Function response in a web page

In my webpage I can use a form action to post a request to run a function on my photon.
The response is defined in the return code in the function that’s called and displayed by the browser.

How do handle the JSON response so that the web page displays a meaningful output rather than the raw JSON?

I don’t really want to leave the page from which the request was made and maybe update an image to show a toggle but as pressed or something like that.

Considering it’s not the first time this question has come up on the forums, have a look: