actually I am retrieving some data mysql from using a PHP query
<?php
$id=$_POST['id'];
$result="SELECT button,row_id,char1,char2,char3,char4,char5,char6,match_time FROM selected_characters WHERE oauth_uid= '".$id."'";
$data = mysqli_query($conn,$result);
while($rows = mysqli_fetch_array($data)){
$JSONDataArray[]=array('button'=>$rows['button'],'rows'=>$rows['row_id'],'time'=>$rows['match_time'],'p1'=>$rows['char1'],'p2'=>$rows['char2'],'p3'=>$rows['char3'],'p4'=>$rows['char4'],'p5'=>$rows['char5'],'p6'=>$rows['char6']);
}
echo json_encode($JSONDataArray);
?>
Here you can clearly see if oauth_uid = $id then data will retrieve otherwise when case is true data is retrieved successfully but when case is not true it give an error
Notice: Undefined variable: JSONDataArray in C:\xampp\htdocs\gaming\php\retrieverb.php on line 24
null
Here is my AJAX
$.ajax({
url: 'php/retrieverb.php',
type: 'post',
data: {id:uuid},
success: function(response) {
var objs = JSON.parse(response);
if(objs!='') {
$.each(objs, function(i, item) {
// var images = document.querySelector('tbody').querySelectorAll('img');
var n = Math.floor(Math.random() *999999);
var distance = (new Date(objs[i].time)).getTime() - (new Date(current)).getTime();
document.getElementById(objs[i].button).remove();
var parent=document.getElementById(objs[i].rows);
var timer = document.createElement("h");
timer.setAttribute("id","timer"+n);
parent.appendChild(timer);
var x = setInterval(function() {
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById("timer"+n).innerHTML ="Tiempo restante: "+ days + "days " + hours + "hours " + minutes + "mins " + seconds + "secs ";
distance -= 1000;
if (distance < 0) {
clearInterval(x);
document.getElementById("timer"+n).innerHTML = "¡El tiempo de partida ha comenzado!";
}
}, 1000);
})
}
else if(objs==''){
alert("ERROR");
}
}
});