Ajax error handling

DHTMLX Touch has 2 predefined error handlers for Ajax calls:

  • error - invokes in case of any error conditions that have resulted while loading.
  • success - invokes in case of successful loading.

Handlers are defined as the third parameter of the load() method. Depending on your needs, you can use both handlers or just one of them.

$$('component_id').load('some_path/data.xml',"xml", {
    error:function(text, xml, XmlHttpRequest){
        alert("error");
    }
});

or

$$('component_id').load('some_path/data.xml',"xml", {
    error:function(text, xml, XmlHttpRequest){
        alert("error");
    },
    success:function(text, xml, XmlHttpRequest){
        alert("success");
    }
});

Parameters of the load() method:

  • path - the data url.
  • datatype - the type of loading data: xml, json or other (optional).
  • callback - the callback function that is called after loading (optional). In the example above the callback is presented as a combination of the error and success functions.

Parameters of the error() and success() functions:

  • text - the full text of the response.
  • xml - the response parsed as xml, if applicable.
  • XmlHttpRequest - the loader object.