res.jsonp([body])
Sends a JSON response with JSONP support. This method is identical to res.json()
, except that it opts-in to JSONP callback support.
res.jsonp(null); // => null res.jsonp({ user: 'tobi' }); // => { "user": "tobi" } res.status(500).jsonp({ error: 'message' }); // => { "error": "message" }
By default, the JSONP callback name is simply callback
. Override this with the jsonp callback name setting.
The following are some examples of JSONP responses using the same code:
// ?callback=foo res.jsonp({ user: 'tobi' }); // => foo({ "user": "tobi" }) app.set('jsonp callback name', 'cb'); // ?cb=foo res.status(500).jsonp({ error: 'message' }); // => foo({ "error": "message" })
Please login to continue.