I want to keep a ajax result into a variable which I will use later. The problem is when I want to use the variable it returns null. I understand that it will for asynchronous programming. But I need to keep the result in a variable. Also I don't want to use async=false method. Below is my code I tried so far.
var column_values=[];
$.ajax({
url: "/get_value/",
type: "POST", // http method
dataType: "json",
async:"false",
data:{
json:prev_value
},
success: function(data){
column_values=data;
},
error: function(error){
alert(error)
}
});
When I tried to access the value of column_values in another function it lengths returns 0.
function get_value(){
let values=column_values.length;
// Here it returns 0
}
What I am doing wrong?