I'm trying to return a string back after my Ajax is executed, however; I'm getting the word undefined instead of the string. I understand that the code is being executed asynchronously, but I don't understand how I can make a solution for my problem.
JS
function aggregator(field){
var query = '{"aggs": { "group_by_date": { "terms": { "field": "' + field + '" } } } }';
$.ajax({
url: 'index.php',
type: 'post',
data: {
qSet: query
},
success: function(message){
return message;
}
});
}
var results = aggregator("transactionDate");
document.getElementById("results").innerHTML = results;
How do I make it so that my element in HTML has the returned value?