JSONP

Sends a JSON response with JSONP support. This method is identical to JSON, except that it opts-in to JSONP callback support. By default, the callback name is simply callback.

Override this by passing a named string in the method.

  1. func (c *Ctx) JSONP(data interface{}, callback ...string) error
  1. type SomeStruct struct {
  2. name string
  3. age uint8
  4. }
  5. app.Get("/", func(c *fiber.Ctx) error {
  6. // Create data struct:
  7. data := SomeStruct{
  8. name: "Grame",
  9. age: 20,
  10. }
  11. return c.JSONP(data)
  12. // => callback({"name": "Grame", "age": 20})
  13. return c.JSONP(data, "customFunc")
  14. // => customFunc({"name": "Grame", "age": 20})
  15. })