[Solved] if statement in success ajax


try this code

change with your code

PHP Code:

$data = array();
if (mysqli_num_rows($execute) >= 1)
{
    $data= array('code'=>100,'message'=>"Precinct is full.\n Recheck precinct number.");
    //echo "Precinct is full.\n Recheck precinct number.";
}else{
    $data= array('code'=>101,'message'=>"Data is empty!");
}

echo json_encode($data);
exit;

ajax code:

var data = JSON.parse(data);
if (data['code'] == 100) {
    alert(data['message']);
}

0

solved if statement in success ajax