0

Unfortunately, JavaScript and jQuery are not my strong points and I have a question that I know has probably been answered before but I cannot quite find the answer I need.

I have the following code:

var JSLib = {
GetLabelTextFromServer: function (GetHandlesArray, callback) {
        $.ajax({
            url: "/sorce/Beacon/PageItem/AppAspx/generic/GetLabel.ashx",
            type: "POST",
            data: JSON.stringify({ 'Labels': GetHandlesArray }),
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                callback(data);
            },
            
        });
    }
}
    var Tst = {
        HTML: function() {
      Labels = ["VIEW_ALL_SCASE"];
        JSLib.GetLabelTextFromServer(Labels, function(LabelData) {
            return '<div class="notificationsShadeFooter"><a href="/sorce/beacon/default.aspx?pageid=notifications" title="Go to the notifications page">' + JSLib.GetLabel(LabelData, "VIEW_ALL_SCASE") +'</a></div>';
        });
    }
}

Tst.HTML();

What I am trying to get to is the return of the text from the inner function passed to GetLabelTextFromServer() but I am not sure if I am on the right path or if what I want to do is even possible.

Can anyone help me?

Thank you in advance for any help that anyone can offer.

jcnewman83
  • 189
  • 1
  • 12
  • 1
    You're using the callback pattern correctly in `GetLabelTextFromServer()`, however the callback you provided then tries to `return` the value which is not possible. You need to receive the `LabelData` argument, then work with it within the callback, either directly or by passing it on to another compartmentalised function. See the duplicate for a clearer description of the issue. – Rory McCrossan Dec 11 '20 at 16:41
  • Thanks for you response @AlonEitan this article has helped me get to where I am but I can not quite get to how I get the return to... well... return the string that is being generated. – jcnewman83 Dec 11 '20 at 16:47
  • 1
    Thanks @RoryMcCrossan that was really helpful, I will set to trying to rework how the chain is called now I understand that the return is definitely not possible. Thank you again – jcnewman83 Dec 11 '20 at 16:50

0 Answers0