I need some help creating Ajax, which I am not familiar with.
This is my actual PHP code that works:
$channels = array("channel1","channel2");
$arrlength = count($channels);
for($x = 0; $x < $arrlength; $x++) {
$ch = curl_init("somemyapiurl".$channels[$x]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$kanal = curl_exec($ch);
$kanal_decode= json_decode($kanal);
$ch_name= $kanal_decode ? 'true' : 'false';
echo "<button type='button' id= '".$channels[$x]."' class='btn btn-success'>"$channels[$x]."</button> ";
echo "<script>
if($ch_name == false) {
document.getElementById('$channels[$x]').className='btn btn-danger';
} </script>";}}
So what I do here is actually for every value in $channels
, I am checking api and create button on page, with default class success.
If API returns value false , then with script I am changing button class.
Until now, I was doing refresh of page for some interval, but now I want to my page do this dynamically without refreshing it and I know I need ajax. Thank you in advance for the help.