Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Pessoal to tentando utilizar um script de atualização de horas. Mas está acontecendo um erro quando atualiza a hora.
Houve um problema ao obter os dados:nForbidden
Esses são os arquivos que estou utilizando.
****
index.html
>
<html>
<script language="javascript" type="text/javascript" src="script.js">
</script>
<div id="relogio"></div>
</html>
****
relogio.php
>
<?
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
echo date("H:i:s");
?>
****
script.js
>
var req;
function loadXMLDoc(url)
{
req = null;
// Procura por um objeto nativo (Mozilla/Safari)
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
// Procura por uma versão ActiveX (IE)
} else if (window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP.4.0"); //alert(req);
} catch(e) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP.3.0"); //alert(req);
} catch(e) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP"); //alert(req);
} catch(e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP"); //alert(req);
} catch(e) {
req = false;
}
}
}
}
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}
function processReqChange()
{
// apenas quando o estado for "completado"
if (req.readyState == 4) {
// apenas se o servidor retornar "OK"
if (req.status == 200) {
// procura pela div id="news" e insere o conteudo
// retornado nela, como texto HTML
document.getElementById('relogio').innerHTML = req.responseText;
} else {
alert("Houve um problema ao obter os dados:n" + req.statusText);
}
}
}
function buscarTempo()
{
loadXMLDoc("relogio.php");
}
// Recarrega a cada 60000 milissegundo (60 segundos)
setInterval("buscarTempo()", 1000);
----------------------------
Tópico Mesclado
----------------------------
Alguém teria um script da data do servidor como um relogio digital?
Esse ai em cima funciona, logo da um erro que nao sei corrigir!
Se algum puder me ajudar!
Carregando comentários...