mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-23 18:22:23 +08:00
document jsonp on the README
This commit is contained in:
parent
15a6d567a2
commit
55fb204001
22
README.md
22
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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user