我目前想要实现的是一个自动图标更新器。到目前为止,我只为 1 个图标工作,但我有 9 个。现在我尝试重复相同的代码 9 次,尝试让它在同一个文件中工作,等等......但没有成功。每个图标都有一个单独的计时器,它将显示不同的图像。(相同的图像不透明度较低)
我想要一个检查数据库时间的东西,看看时间是否到了,如果不显示图像 2,则显示图像 1。
这是我到目前为止的代码:
function runme() {
var ajaxRequest;
try {
ajaxRequest = new XMLHttpRequest();
} catch (e) {
try {
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
return false;
}
}
}
var str = "<?echo$id;?>";
var strhehe = "&rand=" + Math.random();
var strhehes = "&userid=<?echo$id;?>";
var strhehess = "&username=<?echo$name;?>";
ajaxRequest.open("GET", "auto.php?&id=" + str + strhehes + strhehess + strhehe, true);
ajaxRequest.send(null);
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function () {
if (ajaxRequest.readyState == 4) {
if (ajaxRequest.status == 200) {
attempt = 0;
document.getElementById("icon_messaging").innerHTML = ajaxRequest.responseText;
document.getElementById("error_mess").innerHTML = '';
document.getElementById("error_mess").style.display = 'none';
} else {
attempt += 1
document.getElementById("error_mess").style.display = 'block';
document.getElementById("error_mess").innerHTML = '<br><font color="#ff4040" onMouseover="ddrivetip(\'There is an error connecting. The game will continue trying to connect again.\')" onMouseout="hideddrivetip()" style="cursor: pointer;">Error Code: ' + new XMLHttpRequest().status + '<br>Attempts: ' + attempt + '</font>';
}
}
}
setTimeout("runme()", 6000);
}
setTimeout("runme()", 5000);
这是auto.php:
//AUTO INCLUDE
$userids = $_GET['userid'];
$saturate = "/[^a-z0-9]/i";
$saturatesd = "/[^0-9]/i";
$sessionid = preg_replace($saturate,"",$sessionidbefore);
$userid = preg_replace($saturatesd,"",$userids);
$statustest = mysql_query("SELECT newmail,lastactive FROM login WHERE id = '$userids' LIMIT 1");
$statustesttwo = mysql_fetch_array($statustest);
$mails = $statustesttwo['newmail'];
$last_active_1 = $statustesttwo['lastactive'];
if($mails == '0'){
echo "<a id='inboxspan' href='/home.php?pageid=80'><img src='images/mail-yes.gif' style='border-style: none'></a>";
}else{
echo "<a id='inboxspan' href='/home.php?pageid=80'><img src='images/layout/mail-n.jpg' style='border-style: none'></a>";
}