Do not judge strictly - I just started to learn JavaScript.
I check the user's rights and if the user has the necessary rights, then the code is executed. I create an if in which I call a function from another js file. The problem is that js without waiting for a response, then executes the code and therefore the function returns undefined ...
Here is the code:
if (verification(localStorage.getItem("client_id"), localStorage.getItem("verification"))){ ...}
Function code from a separate verification.js file:
function verification (client_id, verification){ $.ajax({ url: "/verification", method: "POST", async: false, data: { client_id: client_id, verification: verification, } }).then(function(res) { return res; }); }
How can I do if wait for an answer?
then) - Igorurl: "/verification", method: "POST", async: false, data: { client_id: client_id, verification: verification, }, success: function(res){ //ваш if, res - это то, что возвратит сервер },- Vitaly Shebanits