2 回答
TA贡献1911条经验 获得超7个赞
dbac 我会尝试你的解决方案,谢谢。与此同时,我使用非常普通的方法让它工作,但它帮助我遵循我自己的代码,因为我是 Javascript/AJAX 的新手。
查询.php
echo "<div id='".$divID."'>".$divOutput."</div>";
行后的 Scoreboard.php:
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var check = xmlhttp.responseText;
if (check.indexOf('race_position_1') >= 0 ) {
document.getElementById('race_position_1').innerHTML = xmlhttp.responseText;
} else if (check.indexOf('race_position_2') >= 0) {
document.getElementById('race_position_2').innerHTML = xmlhttp.responseText;
} else if (check.indexOf('race_position_3') >= 0) {
document.getElementById('race_position_3').innerHTML = xmlhttp.responseText;
} else if (check.indexOf('race_position_4') >= 0) {
document.getElementById('race_position_4').innerHTML = xmlhttp.responseText;
} else if (check.indexOf('race_position_5') >= 0) {
document.getElementById('race_position_5').innerHTML = xmlhttp.responseText;
} else if (check.indexOf('race_name') >= 0) {
document.getElementById('race_name').innerHTML = xmlhttp.responseText;
} else if (check.indexOf('race_number') >= 0) {
document.getElementById('race_number').innerHTML = xmlhttp.responseText;
} else if (check.indexOf('race_sectional_1') >= 0) {
document.getElementById('race_sectional_1').innerHTML = xmlhttp.responseText;
start();
document.getElementById('race_stopwatch').style.border = '1px solid green';
document.getElementById('race_stopwatch').style.color = 'green';
} else if (check.indexOf('race_sectional_2') >= 0) {
document.getElementById('race_sectional_2').innerHTML = xmlhttp.responseText;
} else if (check.indexOf('race_sectional_3') >= 0) {
document.getElementById('race_sectional_3').innerHTML = xmlhttp.responseText;
stop();
document.getElementById('race_stopwatch').style.border = '1px solid red';
document.getElementById('race_stopwatch').style.color = 'red';
} else if (check.indexOf('race_sectional_4') >= 0) {
document.getElementById('race_sectional_4').innerHTML = xmlhttp.responseText;
} else if (check.indexOf('race_margins_1') >= 0) {
document.getElementById('race_margins_1').innerHTML = xmlhttp.responseText;
} else if (check.indexOf('race_margins_2') >= 0) {
document.getElementById('race_margins_2').innerHTML = xmlhttp.responseText;
} else if (check.indexOf('race_run_home') >= 0) {
document.getElementById('race_run_home').innerHTML = xmlhttp.responseText;
} else if (check.indexOf('race_weather_direction') >= 0) {
document.getElementById('race_weather_direction').innerHTML = xmlhttp.responseText;
} else if (check.indexOf('race_weather_wind') >= 0) {
document.getElementById('race_weather_wind').innerHTML = xmlhttp.responseText;
} else if (check.indexOf('race_time_official') >= 0) {
document.getElementById('race_time_official').innerHTML = xmlhttp.responseText;
} else if (check.indexOf('race_time') >= 0) {
document.getElementById('race_time').innerHTML = xmlhttp.responseText;
} else {
// last option catch all
}
那里还有一个 start() 和 stop() - 从GitHub添加一个 Javascript 计时器
添加回答
举报