javascript - Need from PHP code to create Ajax -
i need creating ajax, not familiar with.
this actual php code 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 here every value in $channels
, checking api , create button on page, default class success. if api returns value false , script changing button class.
until now, doing refresh of page interval, want page dynamically without refreshing , know need ajax. thank in advance help.
the way ajax works call out php file, work, uses php echo
command return data ajax code block received in success
function (or .done()
function) - , there have data returned php in variable. can parse (if json object) , iterate through elements build html, or can directly inject returned data (whether php returned html or couple of words or numbers).
this post has simple ajax examples review / experiment with.
Comments
Post a Comment