0

I have a dojo class like this.

    var widget = declare("app.util",null, {
        createSecuredLayers: function () {
           $.ajax.get({
                url: "/Api/GetLayer",
                success: function (e) {
                },
                error: function () {
                }
            });
        }
    });

I want to use this object with callback parameters. I mean I want to pass success and error callbacks as parameter.

    var util = new app.util();
    util.createSecuredLayers({
         success:function(){ },
         error:function(){ }
    });

2 Answers 2

1
createSecuredLayers: function(item) {
    $.ajax.get({
        url: "/Api/GetLayer",
        success: item.successCallback,
        error: item.errorCallback
    });
}

When you call the method, don't forget to pass the response in the success callback.

util.createSecuredLayers({
    successCallback: function(resp) {},
    errorCallback: function(err) {}
});
Sign up to request clarification or add additional context in comments.

Comments

1

You can do it like this:

var widget = declare("app.util",null, {
    createSecuredLayers: function (args) {
       $.ajax.get({
            url: "/Api/GetLayer",
            success: args.success,
            error: args.error
        });
    }
});


var util = new app.util();
util.createSecuredLayers({
     success:function(){ },
     error:function(){ }
});

You should also consider using Dojo's deferred

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.