website icon indicating copy to clipboard operation
website copied to clipboard

JSONP

Open xzavierluol opened this issue 7 years ago • 2 comments

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)

})

xzavierluol avatar Apr 12 '19 09:04 xzavierluol

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"

upupnoah avatar Feb 03 '24 16:02 upupnoah

Just change it to JSONP, and then request like this: GET /JSONP?callback=x HTTP/1.1

upupnoah avatar Feb 03 '24 16:02 upupnoah