在道场获得全球处理所有AJAX调用道场、全球、AJAX

2023-09-10 20:45:48 作者:专属特权

我需要调用一些常用的方法一个AJAX调用之前和(被称为实际处理方法之前)AJAX调用后的成功。我使用 dojo.aspect 来实现这一目标。

I need to invoke some common methods before an AJAX call is made and after the AJAX call (before the actual handler method is called) is success. I'm using dojo.aspect to achieve this.

这是我的code样品

function makeAjaxCall(){
    dojo.xhrGet({
        url:"sample_url",
        content:{
            test:"value"
        },
        load:function(response){
            //Do some logic here
        },
        error:function(response){
            //handle error
        }
    });

}

下面是 dojo.aspect 这我用得到一个钩到 XHR 通话。

Below is the dojo.aspect which I'm using to get a hook to the XHR calls.

define(["dojo/aspect"], function(aspect){
     aspect.after(dojo, "xhr", function(deferred){
        console.log("AJAX AFTER");
        deferred.then(function(response){
            //CALLED AFTER 'load' METHOD IS CALLED.
            console.log("Testing");
        });
     });
    aspect.before(dojo, "xhr", function(method, args){

        console.log("AJAX BEFORE");
    });
});

现在的问题是 deferred.then aspect.after