Check documentation for the latest version 6.0 of dhtmlxSuite onAjaxError DHTMLX Docs

onAjaxError

fires if the server returns an error

void onAjaxError(object request){ ... };

Parameters

requestobjectXML HTTP request object
Details

When server side determines some conditions like it's impossible to return a valid response or it's necessary to notify a user about some parsing errors or something else, you can return custom response code:

<?php
 
// some code
 
if (some_conditions == true) {
    // valid response goes here
} else {
    // set custom response code, 520 here just as an example
    http_response_code(520);
    // optionally, you can send your custom error code/description,
    // for example, those which are inner code/descr in your app
    print_r("{error_code: 122, error_descr: 'incorrect user id'}");
}
 
?>

To handle it on the client side, you need to add a handler for onAjaxError event:

window.dhx.attachEvent("onAjaxError", function(r){
 
    // check, if any server response can be retrieved
    var t = dhx.s2j(r.xmlDoc.responseText);
 
    // optionally, you can set your own one, if server has returned nothing
    // or if the response is invalid
    if (t == null) t = {error_code: 1, error_descr: 'unknown server error'};
 
    // here your rest code, notify a user or so
    // ...
 
});

Then any data loading via dhx.ajax or component.load() will trigger onAjaxError event, if the response code will be any other than 200.

Change log

added in 4.1

Back to top