AJAX Javascript元素未更新


AJAX Javascript Element not updating

我的InternetExplorer/EDGE浏览器有问题。基本上,我有一个从远程XML文件中提取数据并在页面中显示的脚本(实际示例:http://www.oldiesplus.com/-页面顶部的无线电信息部分)

它的工作方式是每15秒读取一次XML文件,并更新歌曲标题(这是滚动位)。这在谷歌Chrome浏览器的IE/EDGE下运行得很好,但脚本会执行(请参阅控制台日志),但元素从未更新。

使用Curl获取XML文件,并将CURLOPT_FRESH_CONTENT设置为true。

那么,问题是,为什么元素没有随着IE/EDGE中的新内容进行更新?

这里有一些代码可以帮助:

sc_conn.inc(PHP):

$ch             = curl_init($sc_host . '/admin.cgi?mode=viewxml');
    curl_setopt($ch, CURLOPT_PORT, $sc_port);
    curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERPWD, $sc_admin.':'.$sc_pass);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
    $curl = curl_exec($ch);

shoutcast.js(JavaScript):

function getStreamData() {
        var ajax;
        if (window.XMLHttpRequest) {
                ajax = new XMLHttpRequest();
        } else {
                ajax = new ActiveXObject("Microsoft.XMLHTTP");
        }
        ajax.open('GET','/sc_data.php', true);
        ajax.send();
        ajax.onreadystatechange = function() {
                if (ajax.readyState == 4 && ajax.status == 200) {
                        var data = ajax.responseText.split("|");
                        var song = (data[1] == '') ? 'some music.' : data[1];
                        var cta = (player_state == 0) ? '/new/img/play.png' : '/new/img/pause.png';
                        if (data[2]) {
                                document.getElementById('radio-info').innerHTML = '<h2>'+data[2]+'</h2>';
                                document.getElementById('radio-info').innerHTML += '<p><span class="dj_name">'+data[0]+' is playing</span> '+song+'</p>';
                        }else{
                                document.getElementById('radio-info').innerHTML = '<p><span class="dj_name">'+data[0]+' is playing</span> '+song+'</p>';
                        }
                        document.getElementById('tunein').src = cta;
                        console.log("Title Updated!");
                }
        }
}

解决方案是绕过AJAX请求的缓存-使用在PHP脚本调用的末尾添加一个随机数

Math.random();