From 55fb204001b435ed3d7ae9729f484f99cb94226b Mon Sep 17 00:00:00 2001 From: w169q169 Date: Wed, 25 Apr 2018 14:41:02 +0800 Subject: [PATCH] document jsonp on the README --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 6c8988e7..481ef36c 100644 --- a/README.md +++ b/README.md @@ -861,6 +861,28 @@ func main() { r.Run(":8080") } ``` +#### JSONP + +Using JSONP to request data from a server in a different domain. Add callback to response body if the query parameter callback exists. + +```go +func main() { + r := gin.Default() + + r.GET("/JSONP?callback=x", func(c *gin.Context) { + data := map[string]interface{}{ + "foo": "bar", + } + + //callback is x + // Will output : x({\"foo\":\"bar\"}) + c.JSONP(http.StatusOK, data) + }) + + // Listen and serve on 0.0.0.0:8080 + r.Run(":8080") +} +``` ### Serving static files