Development AJAX

From Cloudrexx Development Wiki
Jump to: navigation, search

JsonData for Contrexx 3

-> see JsonData

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)

Example:

jQuery.ajax({
  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
JS::activate('cx');
Handling request
// read transmitted data from GET request
$payload = json_decode($_GET['payload']);
 
// perform some operations ...

// return response
die(json_encode($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.