gin-gonic / website

Official website and document for Gin
https://gin-gonic.com/
MIT License
120 stars 199 forks source link

JSONP #74

Open xzavierluol opened 5 years ago

xzavierluol commented 5 years ago

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)

})

upupnoah commented 7 months ago

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 commented 7 months ago

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