website
website copied to clipboard
JSONP
the code in https://gin-gonic.com/zh-cn/docs/examples/jsonp/ r.GET("/JSONP?callback=x", func(c *gin.Context) { data := map[string]interface{}{ "foo": "bar", }
// callback 是 x
// 将输出:x({\"foo\":\"bar\"})
c.JSONP(http.StatusOK, data)
}) need to be: r.GET("/JSONP", func(c *gin.Context) { data := map[string]interface{}{ "foo": "bar", }
// callback 是 x
// 将输出:x({\"foo\":\"bar\"})
c.JSONP(http.StatusOK, data)
})
According to his example, it should return x({"foo":"bar"}), but I used the following command and got a 404 not found.
[GIN] 2024/02/03 - 23:57:59 | 404 | 730ns | 127.0.0.1 | GET "/JSONP?callback=x"
Just change it to JSONP, and then request like this: GET /JSONP?callback=x HTTP/1.1