I'm trying to return data from a callback function, but it doesn't work... Instead it just returns "undefined".
Code(JS):
var apiUrl = "/dev/mysqlApi/api.php";
function api(actionType, newArray)
{
    if(typeof newArray == "undefined")
    {
        $.ajax({ url: apiUrl, type: "POST", data: { actionType: actionType }, success: function(data){ returnData(data); } });
    }
    else
    {
        $.ajax({ url: apiUrl, type: "POST", data: { actionType: actionType, newArray: newArray }, success: function(data){ returnData(data); } });
    }
    function returnData(data)
    {
        return data;
    }
    return returnData();
}
 
    