0

I'm relatively new to Javascript. I am trying to call a function after an Ajax call returns, as it relies on values from both the Ajax call and the preceding code. The function is externally defined because I use it for multiple calls and don't want to duplicate code. However, I am getting an error stating the external function is not defined. Here's a mockup of my JS code, and the error I am getting:

var ContainingObject {
    FunctionForAfterwards: function (responseObject, externalData) {
        /* Do stuff and things */
    },
    
    FunctionWithAjaxCall: function () {
        var externalData = "stuff and things";
        $.ajax({
        url: '/My/Url/',
        data: JSON.stringify(RequestData),
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        success: function (response) {
            FunctionForAfterwards(response, externalData);
        }
        });
    }
}

The error I am getting looks like this:

ReferenceError: FunctionForAfterwards is not defined

I have also tried using this.FunctionForAfterwards but to no avail. I'm sure this is possible, but I simply don't have the knowledge to make it happen.

Inglonias
  • 468
  • 1
  • 5
  • 18

0 Answers0