라디오 웹 사이트에서 자바 스크립트 노래 카운트 다운을 사용합니다. 매 10 초에서아약스 호출로 인해 자바 스크립트 카운트가 지연됩니다.
, 카운트 다운 시차는 새 노래가 있는지 확인하기 때문에 아약스 호출의 (1 하나 더 초 건너 뛰기) :
function getcursong(){
var result = null;
var scriptUrl = "get_current_song.php";
$.ajax({
url: scriptUrl,
type: 'get',
dataType: 'html',
async: false,
success: function(data) {
result = data;
}
});
return result;
}
콘솔에서 보면, 나는
GET
볼 통화에는 약 2 초가 걸립니다.
get_current_song.php
은 curl
을 사용하여 icecast 서버에서 현재 노래를 가져옵니다.
아약스 호출로 인해 카운트 다운이 지연되는 것을 막기 위해 할 수있는 일이 있습니까?
이하는 get_current_song.php
입니다.
<?php
require('config.php');
$current_song = getStreamInfo();
function url_get_contents($Url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_TIMEOUT,2);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
function getStreamInfo(){
$str = url_get_contents(SERVER.'/status.xsl?mount='.MOUNT);
if(preg_match_all('/<td\s[^>]*class=\"streamdata\">(.*)<\/td>/isU', $str, $match)){
$x = explode(" * ",$match[1][9]);
return $x[1];
}
}
?>
<?php
echo $current_song;
?>
@ ASYNCHRONOUS 통화 동기화를하지 마십시오.) – Andreas
@Jeffman이 맞습니다. 필요하지 않다면'async : false' (기본은 암시 적'async : true')를 제거하십시오. – ale
고마워요! 그것은 그 것이었다. – trogne