Using the JSONP response formatter

Last updated on
30 April 2025

Due to the same origin policy, it's difficult to communicate with servers on other domains using JavaScript. JSONP ("JSON with padding") is a popular technique used to overcome this limitation. See Wikipedia for more details on how JSONP works.

To enable JSONP for your service, simply go to its Server tab (select "Edit server" from the dropdown for your service on admin/structure/services), check the "jsonp" checkbox and click Save.

To use JSONP with your service, you need to:

  1. Use the Accept: application/javascript HTTP header (not application/json)
  2. Append a callback=myFunction parameter to the URL, telling the service which function name to use

JavaScript libraries such as jQuery may support JSONP, taking care of this for you behind the scene. See e.g. .getJSON and .ajax.

The resulting URL might look something like this:
http://example.com/myservice/node/index?callback=fetchAllNodes

Help improve this page

Page status: Not set

You can: