The aim is to get the value from the Ajax success and use it in another function;
I have attached the code below:
Code:
let neededvalue;
$(function(callback){
$.ajax({
type:'GET',
url: 'getfile.php',
data:{
'file':file,
},
success: function(data){
neededvalue = data.split(","); // 24,23,100,106
console.log(neededvalue[0]) //23
console.log(neededvalue[1]) //24
console.log(neededvalue[2]) //100
console.log(neededvalue[3]) //106
$('#img01').selectAreas({
onChanged: debugQtyAreas,
maxAreas:1,
areas: [
{
x: neededvalue[0],
y: neededvalue[1],
width: neededvalue[2],
height: neededvalue[3],
}
],
parent: $('#myModal'),
});
callback(neededvalue);
}
})
})
In the above code, when I checked the values of neededvalue that i received from ajax Get, it prints the correct values in the log. I added those values to the side of the variables in the code above. The problem that I face is when I try to use the values of neededvalue[0],neededvalue[1],neededvalue[2],neededvalue[3] and use them inside the function selectareas. I could not place the values from 'neededvalue' to variables x, y , width and height.
I tried to run the code with direct values to variables inside selectareas i.e., x=23, y=24, width =100 and height=106 and I was able to make the box over the image.
But I dont know why I can not use the values of "neededvalue" and assign it to the variables of selectareas x,y,width and height.
Can someone help me to fix this issue and help me assign the values from ajax success function to SelectAreas function