I am trying to use AJAX to call a Go API that inserts data into Postgresql.
-
This is the query that is executed in Postgresql. Which work as query
DB Fiddle - SQL Database Playground -
This is the API that inserts the query to Postgresql (using sqlx):
func endpoint { //simplified
data = new(query, val)
json.NewEncoder(w).Encode(data)
func new(query string, val string) interface{} {
data := db.MustExec(query, val)
return data
}
- This is the AJAX code that sends the REST request for all headers:
Edit fiddle - JSFiddle - Code Playground
OR this correct code for the text header that responds{"Locker":{}}
:
Edit fiddle - JSFiddle - Code Playground
The desired result should be {“tsk_id”: “33”} (newly inserted number)
My goal is to fetch the newly added tsk_id from the INSERT INTO
It seems that the headers from MustExec not is updated or converted correctly.
Any clue welcome!