functions.js
function clients(id){
var result = '';
$.ajax({
type: "GET",
url: "classes/response.php?type=clients",
data: {id: id},
success: function(data){
result = data;
console.log(result); // retrieves 'John'
console.log(data); // retrieves 'John'
}
});
return result;
}
And in my other file main.js
$("#client_check").on('click', function(){
var input = $("#client_id");
var name = clients(input.val());
console.log(name); // retrieves empty
$("#client_id").val('');
});
Shouldn't this work? The function output the value perfectly, but when I call the function to a variable it retrieves empty.
What am I doing wrong?