Development AJAX

From Cloudrexx Development Wiki
Jump to: navigation, search

Note: This documentation refers to version 2.x. For newer versions of Cloudrexx, please refer to Exposed methods.

Client Side

The easiest way to make a AJAX (XMLHttpRequest) call is to use the AJAX capabilities of jQuery.

Don't forget to load the Contrexx Javascript Framework or at least jQuery (see Server Side implementation below)


  type: 'GET',
  url: cx.variables.get('cmsPath', 'contrexx') + 'index.php',
  data: { section: 'MODULE', cmd: 'CMD', standalone: true, payload: jsondata},
  success: fnSuccess,
  dataType: json

Passing the argument standalone to the ajax-request will speed up the handling of therequest by deactivating any system components (template, navigation, etc) that won't be required by a ajax call.

Server Side

This feature is replaced by JsonData in Contrexx 3 and newer!

Load required Javascript libraries
Handling request
// read transmitted data from GET request
$payload = json_decode($_GET['payload']);
// perform some operations ...

// return response
Helper functions
Note: Contrexx implements a wrapper (using [1] PEAR's Services_JSON) to provide these functions even when PHP was compiled without JSON extension. The optional parameters you can pass to the functions json_encode() and json_decode() have not been implemented by the wrapper class. Therefore you should not depend on using those parameters.