Callback after each successful ajax request

Hi,

I need to check a HTTP header after ajax request. (Ideally after each ajax request)

For that I need an access to a XmlHttpRequest to get the HTTP response header.

I can do it in a custom proxy, in the “result” method. But I don’t know how to use a proxy with the webix.ajax() method.

Do you know how to do that ?

There is a better way to perform my goal ?

Thanks

Like everyone else, I managed by overriding webix.ajax.method.$callback :

webix.ajax.original_callback_function = webix.ajax.$callback;
webix.ajax.$callback = function(owner, call, text, data, x, is_error) {

    // My custom code here

    return webix.ajax.original_callback_function(owner, call, text, data, x, is_error);
};

Hi,

the solution you found will work for both cases:

  • load method calls
  • webix.ajax() calls

However, it will be better to use the following call for the original method (in case the method will get more parameters):

webix.ajax.original_callback_function = webix.ajax.$callback;

webix.ajax.$callback = function(owner, call, text, data, x, is_error) {
    // My custom code here
    return webix.ajax.original_callback_function.apply(this,arguments);
};

its Not Support in webix 6.x

webix.ajax.original_callback_function = webix.ajax.$callback;

webix.ajax.$callback = function(owner, call, text, data, x, is_error) {
// My custom code here
return webix.ajax.original_callback_function.apply(this,arguments);
};

Hello,

In version 6.1 we have improved loading a lot to allow for custom loading patterns.

Now you can watch each Ajax request sent by Webix (and access its parameters) with the onBeforeAjax event:

webix.attachEvent("onBeforeAjax", 
    function(mode, url, params, x, headers, files, defer){
   //x is request object
   //defer is promise created for the request

   defer.then(function(data){
     console.log("response", data.json());
   }, function(x){
     console.log("err", x)
   });

});

Here is the snippet:

https://snippet.webix.com/7sgys4gn