I created an AJAX function that takes two arguments, sends them to a script in PHP and formats them as I wish, like this :
function createUniqueKey (arg1, arg2) {
$.post("/ajax/documents.php", {arg_1: arg1, arg_2 : arg2}, function(data){
console.log(data) //Good result
return data
}, "text");
}
When the user clicks a button, it starts the ajax request, the problem is that I can not assign it to a variable, I tested that but without success
$('#btn').click(function() {
...
var uniqueKey = createUniqueKey(arg1, arg2)
console.log(uniqueKey) //undefined
...
});
The console.log
present in the function gives me a result but the console.log
of the variable returns me undefined
How to sign the result to the variable (uniqueKey
)?