Here's my function getState, which makes an ajax call:
var getState = function(_id, callback) {
    $.ajax({
        url: hostGlobal+"site/estrutura/ajax.php",
        type: "POST",
        dataType: "HTML",
        data: {
            action: "getState",
            id: _id
        },
        success:function(result, textStatus, jqXHR) {
            callback(result);
        },
        error: function(jqXHR, textStatus, errorThrown) { 
        }
    });
}
And here I use the resulting string for concatenation:
"<li class='list-group-item listItem' id='state" + i + "'><strong>Estado:</strong><span class='listSpan'> " + getState(result[i]["estado"], function(x) { return x; }) + "</span></li>" +
Since that return statement does not work, since it returns for the anonymous function instead of the getState, I try to modify the contents of the element:
... + "<li class='list-group-item listItem' id='state" + i + "'><strong>Estado:</strong><span class='listSpan'> " + getState(result[i]["estado"], function(x) { $("#state" + i).html(x); }) + "</span></li>" + ...
But "undefined" is everything I get. I know I'm not using the callback properly, but I'm failing to understand how...
 
    