Asyncronous function not changing variable in JS

var encodedAccount = '';
function encodeUsername() 
{
    encodedAccount=  encrypt(document.getElementById('account').value);
    alert(encodedAccount);
}

the function encrypt is async ajax function. the alert is not returning a value , it's still '' Any Idea ? Thanks

Answers


Asynchronous functions generally don't return values. They usually accept a callback function that fires when the function is done (usually when when HTTP response comes back in the case of Ajax).

You need to find out how the encrypt function expects to be used and conform to its expectations.


Need Your Help

SBCL surprise lapse into floating point?

common-lisp sbcl org-babel

Consider the following code in Common Lisp: