webCOMAND

ajax::set_data()

Set key/value pairs to be sent back with the AJAX response when subsequently sent with ok(), error() or respond().  Multiple calls to set_data will add data to be sent.  If data is provided that overlaps with existing keys, those values will be updated/overwritten with the new values.

Prototype

boolean set_data(array $data)

Parameters

  • data - Associative array with the key/value pairs that represent the data.

Return

Always returns TRUE.

Example

// return AJAX JSON response as if $ajax->include_all()
// was called, to produce:
// {
//     "Result": "ERROR",
//     "Timestamp": "2017-12-12 14:22:04",
//     "Message": "Custom error.",
//     "Data": {
//         "key1": "value3",
//         "key2": "value2"
//     }
// }
$ajax = new \io_comand_web\ajax();
$ajax->set_data(['key1'=>'value1']);
$ajax->set_data(['key2'=>'value2']);
$ajax->set_data(['key1'=>'value3']);
$ajax->error('Custom error');

Related

ok(), error() or respond()