I have a function that returns an ajax get response:
var myAjaxFunction = function () {
   $.get("/Page1/Index?handler=MyFunction",
        { itemId: itemId})
       .done(function (response) {
           return response;
        })
        .fail(function () {
            return null;
        });
}
This function is called and response is assigned to a variable.
var pendingOperation = myAjaxFunction();
Debugging, the problem that I'm seeing is that if I put a breakpoint on or after the pendingOperation line, it remains undefined. If I continue after the breakpoint, it then hits myAjaxFunction and I can see it tries to return a response containing data. By that point, it is already too late and pendingOperation is undefined. How can I guarantee that myAjaxFunction waits for the get/fetch of data and successfully returns my response before moving on?
 
    