I know this has been asked several times and I have read several answers about the callbacks, but I'm still very confused how to apply to my situation. I have an ajax function being called from within the success of a second ajax function. The result of the embedded ajax is always undefined.
Jquery:
$('#mergeModal').on('show.bs.modal', function (e) {
            // get the list of groups
            $.ajax({
                type: "GET",
                url: '@Url.Action( "GetGroups", "Tally" )',
                data: { contractId: $("#contractId").val()  },
                success: function (data) {
                    // empty then refill groups table
                    $("#groupsTable tbody").empty();
                    for (var key in data.groups) {
                        var groupParts = data.groups[key].split("::");
                        $("#groupsTable tbody").append("<tr id='" + groupParts[0] + "'><td>" + groupParts[1] + "</td><td>" + groupParts[2] + "</td></tr>");
                    }
                    // highlight first row and show appropriate students in students table
                    $("#groupsTable tbody tr:first").css("background-color", "#FFFF7F");
                    var groupID = $("#groupsTable tbody tr:first").attr('id');
                    console.log("groupID: " + groupID);
                    var students = getStudents(groupID);
                    console.log("students: " + students);
                    if(students != "false") {
                        for(var student in students.sellers) {
                            console.log(student);
                        }
                    }
Here is the getStudents function:
function getStudents(group) {
            $.ajax({
                type: "GET",
                url: '@Url.Action( "GetSellers", "Tally" )',
                data: { groupId: group, contractId: $("#contractId").val()  },
                success: function (data) {
                    return data;
                },
                error: function() {
                    return "false";
                }
            });
        }
 
    