Golang how does the background of writing a web project return json data to the front end instead of displaying it directly on the page?

the separation of front and rear ends is not mentioned in the go web programming book, and beginners are confused in learning. I use fmt.Fprint to write json data to the page. How to call the interface at the front end, I return the json data instead of writing it directly on the page

Apr.05,2021

func handler(w http.ResponseWriter, r *http.Request){
    var body json.RawMessage
    // todo
    
    b, _ := body.MarshalJSON()
    w.Header().Set("Content-Length", strconv.Itoa(len(b)))
    w.Write(b)
}

do your processing in todo


api, in http mode can be seen in the browser, and the front-end page can get the value in ajax mode.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea7394-1e40.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea7394-1e40.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?