Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

This function performs identically to ajax(), except the function will attempt to evaluate the response as a JavaScript object. If successful, the resulting object is passed to the handler function (or returned from the function for synchronous requests). This function is designed to be used in requests that return JSON data for client-side processing.

For more information about this function, see the ajax( url or config ) API documentation.

For the options that may be passed in the 'config' object, see the pui.AjaxRequest object documentation.

Like the ajax() function, data in the 'params' property will be treated as a set of name/value pairs, not as JSON data. If you wish to send JSON data, use the reqData parameter instead. Using the reqData parameter requires AjaxLibrary version 1.5.9 or Profound UI 6 fix pack 3.0 or newer. See the second example below.

Example:

In this example, the ajaxJSON() function is used to perform an asynchronous POST request.  The customerNumber parameter is send as a URL-encoded name/value pair. The data returned from the request is automatically evaluated into a JavaScript object:

Code Block
javascript
javascript
ajaxJSON({
  url: "getInfo.pgm",
  params: {
    customerNumber: "123"
  },
  method: "post",
  handler: infoHandler
});
function infoHandler(obj) {
  alert("Customer name: " + obj.name);
  alert("Customer phone number: " + obj.phone);
}

 

In this example, the 'customer' JavaScript object is sent as a JSON object using the reqData option, and the output from the server is returned in the 'response' object.  This requires AjaxLibrary 1.5.9 or Profound UI 6 fix pack 3.0 or newer:

Code Block
themeEclipse
languagejavascript
var customer = {
   number: 123,
   name: "ACME, Inc",
   phone: "123-456-7890"
}

ajaxJSON({
     url: "addCust.pgm",
     params: {
       AUTH: encodeURIComponent(pui.appJob.auth)
     },
     headers: {"content-type": "application/json"},
     reqData: JSON.stringify(customer),
     method: "POST",
     handler: function(response) {
        // 'response' will be a JavaScript object that represent's the HTTP server's JSON response
     }
  });