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>&nbsp";  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

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -