Projjex API

Using Remote JSON

Overview

Our goal with the Projjex™ API was to give you the ability to access your data from any environment you choose, including JavaScript code running in a client browser.

The "Web 2.0" paradigm usually involves building web applications using AJAX, and that often means making use of the XmlHttpRequest object. However, browser security restrictions prevent the XmlHttpRequest object from being used across domains (cross-domain scripting). This means that you cannot call the Projjex™ API using the traditional AJAX methods from your own domain.

Remote JSON (also called JSON-P) was designed to solve this problem and provide a safe, secure method of calling JavaScript from another domain.

The idea behind Remote JSON is that, while XmlHttpRequest are not allowed across domains, JavaScript code coming from multiple domains can still interact with each other. Remote JSON provides a way to retrieve data in JSON format from one domain (the Projjex™ API) and use that data in the JavaScript code on another domain (your application).

This method of transferring data is used by a number of leading web applications. For a thorough introduction to Remote JSON we recommend you read through the introduction given by Yahoo: http://developer.yahoo.com/common/json.html.

Remote JSON works by wrapping the JSON data in a callback function call. Examples of JSON formatted data and a Remote JSON response are shown here:

JSON Data

{ "Login": {"Firstname": "Alex", "Lastname": "Bubbagum", "Session": "UJ0X23LRZPR1AFX5YKF4" }}

Remote JSON

handleProjjexData({ "Login": {"Firstname": "Alex", "Lastname": "Bubbagum", "Session": "UJ0X23LRZPR1AFX5YKF4" }});

In the second example, the response is calling a method named handleProjjexData and passing it the JSON formatted data. This enables you to add a method within your own JavaScript code named handleProjjexData and process the data there.

To get a result in the format, simply add a parameter named Output with a value of "json" to any API call. If you want to change the function name to something other than handleProjjexData, simply add a parameter named Callback and set the value to whatever function name you prefer.

Example Remote JSON Call

Replace user@domain.com and pwd with your email address and password to use this sample:

<html>
   <head>
     <script type="text/javascript">
       function loginCallback(result) {
         if (result.Error) {
           alert ('Error: ' + result.Error.value);
         }
         else {
           alert('Your first name is ' + result.Login.Firstname);
           alert('Your last name is ' + result.Login.Lastname);
           alert('Your session token is ' + result.Login.Session);
         }
       }
     </script>
     <script type="text/javascript" src="https://api.projjex.com/login/?email=user@domain.com&password=pwd&output=json&callback=loginCallback"></script>
   </head>
   <body>
   </body>
</html>

Open Source Libraries

For more advanced uses of Remote JSON, we recommend you look at some of the JSON-P scripting libraries available.

An open source JSON library is available at http://www.json.org/json.js.

If you use the mootools JavaScript libraries, you may also be interested in CNET JSON-P extension at http://clientside.cnet.com/wiki/cnet-libraries/06-request/00-jsonp

Or, for jQuery see the getJSON method at http://docs.jquery.com/Release:jQuery_1.2/Ajax#Cross-Domain_getJSON_.28using_JSONP.29.

Quick Links
Support

.NET developers can download our .NET API Wrapper. The wrapper simplifies using the Projjex™ API by returning .NET objects.

API Methods