Closed naseer2426 closed 3 years ago
So, the problem you are running into is that AJAX is asynchronous. Therefore, the code inside the AJAX will only run after the rest of the code executes. To make your code run synchronously, add the following attribute into your settings JSON.
"async": false
Thank you that worked. I changed my settings to:
var settings = {
"url": "https://"+baseURL+"/api/v2/admins/"+admin+"/users",
"method": "GET",
"headers":{
"Authorization": "Bearer "+token
},
"async":false
};
Your issue/question: I am not able to assign a variable inside the .done function of my ajax call.
What you expect to achieve I need it to assign the value of response to a variable so that i can use it later.
What happens instead The value of the variable becomes null when I call it outside the .done function.
Screenshots The code I wrote
Line 37 is the console.log outside the .done function and line 34 is the console.log inside the .done function.
Your system/software details Windows 10 using Google Chrome