Last updated 26 September 2012. Created on 15 September 2011.
Edited by jackbravo, ximo. 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:

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