Reputation: 11
I am using beego (golang framework) and I am trying to use jquery ajax to update my web pages after the go function finishes. However I am stocked at returning JSON object so that the jquery could handle it in its success function. Is there any way to return JSON in golang or beego and how? Thanks.
Upvotes: 0
Views: 2389
Reputation: 21
type Data struct {
//Values that equivalent to your ajax post
Data string
Id int
Name string
}
var data Data
req := this.Ctx.Request
dec := json.NewDecoder(req.Body)
err := dec.Decode(&data)
if err == nil {
this.Data["JSON"] = &data
this.ServeJSON()
}
Dont forget to import encoding/json
Upvotes: 1