I would like to show client another page after data has been collected from previous page. But I have trouble redirect the new URL on the server side. Here is my logic:
- submit user input with POST action to server;
- server run function saveChoice() to save user input into a database;
- After user input is saved, server send a new URL to client;
- By the time the client GET the new URL, server reads the database and get saved data out
And I am stuck on step 3 (here is an example of the flow):
type Stuff struct{ List []string } func checkcheck(w http.ResponseWriter, r *http.Request) { sinfo := Stuff{ List: some_slice } t, err := template.New("").Parse(tpl_ds) checkErr(err) err = r.ParseForm() checkErr(err) err = t.Execute(w, sinfo) checkErr(err) if r.Method == "POST" { saveChoice(r.Form["choices"]) /* step 3: make user open another URL */ } } And here is the template:
<html> <script> $(function () { $('form').on('submit', function (e) { e.preventDefault(); $.ajax({ type: 'post', data: $('form').serialize(), }); }); }); </script> <body> <form method="POST"> {{range .List}} <input type="checkbox" name="choices" value="{{.}}"> <span>{{.}}</span><br> {{end}} <input type="submit" value="Submit"> </form> </body> </html> May I know how I can redirect to a new page?
p.s. If I put URL on button, then server is not going to run saveChoice()