I'm working on a live update chart, and for that, I made a separate file with the data I need. I made a request on my main page with AJAX so I could get the Array into the main page. But for some reason, I can't use this array outside the request. I would need to use this arrays inside the part only.
Here's what I have:
<script>
$(document).ready(function(){
$.getJSON("loadchart.php", function(data){
var sensor1 = data[0];
var sensor2 = data[1];
var sensor3 = data[2];
var sensorsum = data[3];
});
});
console.log(sensor1);
//My chart stuff down here
When I try to console log of the array it gives an error:
Uncaught ReferenceError: sensor1 is not defined
at main.php:107
This is the new function I tried:
async () => {
async function foo() {
return $.ajax({
url: "loadchart.php",
success: function(data){
return data;
}
});
}
var result = await foo();
console.log(result);
};