MCPcopy
hub / github.com/gin-gonic/gin / JSONP

Method JSONP

context.go:1194–1201  ·  context.go::Context.JSONP

JSONP serializes the given struct as JSON into the response body. It adds padding to response body to request data from a server residing in a different domain than the client. It also sets the Content-Type as "application/javascript".

(code int, obj any)

Source from the content-addressed store, hash-verified

1192// It adds padding to response body to request data from a server residing in a different domain than the client.
1193// It also sets the Content-Type as "application/javascript".
1194func (c *Context) JSONP(code int, obj any) {
1195 callback := c.DefaultQuery("callback", "")
1196 if callback == "" {
1197 c.Render(code, render.JSON{Data: obj})
1198 return
1199 }
1200 c.Render(code, render.JsonpJSON{Callback: callback, Data: obj})
1201}
1202
1203// JSON serializes the given struct as JSON into the response body.
1204// It also sets the Content-Type as "application/json".

Callers 2

TestContextRenderJSONPFunction · 0.80

Calls 2

DefaultQueryMethod · 0.95
RenderMethod · 0.95

Tested by 2

TestContextRenderJSONPFunction · 0.64