Witam chciałbym przez funkcje w JS wczytać obrazek z pliku php (na FireFox działa, lecz na chromie nie)
Plik JS
$(document).ready(function(){
var content = document.getElementById('statusimg');
var call = function(){
$.ajax({
method: 'POST',
url: 'radio/statusimg.php',
success:function(data){
content.innerHTML = data;
setTimeout(call, 30000); // 30s.
}
});
}
call();
});
Plik PHP który posiada 3 obrazki które zmieniają się względem statusu servera
<?php
$online = '<img src="../image/green.png" title="O N L I N E" >'; // Displays when stream is online
$offline['server'] = '<img src="../image/blue.png" title="P A U Z A" >'; // Displays when server is offline
$offline['source'] = '<img src="../image/red.png" title="O F F L I N E">'; // Displays when server is online with no source
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "s8.myradiostream.com:7882/7.html");
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$data = curl_exec($ch);
curl_close($ch);
$data = str_replace('</body></html>', "", $data);
$split = explode(',', $data);
if (empty($data)) {
$status = $offline['server'];
} else {
if ($split[1] == "0") {
$status = $offline['source'];
} else {
$status = $online;
}
}
echo $status;
?>
Jeszcze status GG: Link do pliku PHP
<?php
$numerGG = "1426028";
$status = fopen("http://status.gadu-gadu.pl/users/status.asp?id=$numerGG&styl=2", "r");
$obrazek = fgets($status, 2);
if ($obrazek == '1') { echo '<img src="../home/niedostepny.png" class="gg" >'; }
elseif ($obrazek == '2') { echo '<img src="../home/dostepny.png" class="gg" >'; }
elseif ($obrazek == '3') {echo '<img src="../home/zarazwracam.png" class="gg" >'; }
else { echo 'Brak połączenia z serwerem.'; }
?>
Wywołany przez JS
$(document).ready(function(){
var content = document.getElementById('gg');
var call = function(){
$.ajax({
method: 'POST',
url: 'home/gg.php',
success:function(data){
content.innerHTML = data;
setTimeout(call, 30000); // 30s.
}
});
}
call();
});
kod w html
<img id="gg" class="gg" title="Status GG" />
Jednak ta sama sytuacja co z obrazkami, czyli na chromie nie działa