Last updated September 26, 2012. Created by ximo on September 15, 2011.
Edited by jackbravo. Log in to edit this page.

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

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.