Witam. Mam na stronie diva który się odświeża i pokazuje logi. Chciałem zrobić jeszcze dynamiczny div pokazujący liczbę pozostałych punktów. Jednak po dodaniu drugiego takiego "odświerzacza" na stronie oba przestały działać :/
Jak użyć kilku poniższych skryptów aby działały?
KOD
index.php
<script src="ajax.js"></script>
<strong>Logi</strong>
<script type="text/javascript"><!--
refreshdiv();
// --></script>
<div id="timediv"></div>
ajax.js
// Customise those settings
var seconds = 1;
var divid = "timediv";
var url = "boo.php";
////////////////////////////////
//
// Refreshing the DIV
//
////////////////////////////////
function refreshdiv(){
// The XMLHttpRequest object
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Your browser does not support AJAX.");
return false;
}
}
}
// Timestamp for preventing IE caching the GET request
fetch_unix_timestamp = function()
{
return parseInt(new Date().getTime().toString().substring(0, 10))
}
var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;
// The code...
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp.responseText;
setTimeout('refreshdiv()',seconds*1000);
}
}
xmlHttp.open("GET",nocacheurl,true);
xmlHttp.send(null);
}
// Start the refreshing process
var seconds;
window.onload = function startrefresh(){
//setTimeout('refreshdiv()',seconds*1000);
setTimeout('refreshdiv()',seconds*500);
}
boo.php
<?php
// Configure connection settings
$host="xxxxxx"; // Nazwa hosta.
$db = 'xxxxxx';
$db_admin = 'xxxxx';
$db_password = 'xxxxxxx';
$tablename = 'test';
// Title
//echo "Contents of the table:";
// Connect to DB
// Fetch the data
//$query = "SELECT * FROM $tablename ORDER BY id DESC";
///$query = "SELECT * FROM $tablename";
//$result = mysql_query($query);
// Return the results, loop through them and echo
$result = mysql_query("SELECT * FROM $tablename ORDER BY id DESC LIMIT 8",$sql) or
die ("nie wykonalem");
echo ' '.$roww[1].' '.$roww[2].' '.$roww[3].' '.$roww[4] .'<br>' ; }
?>
Może lepiej to będzie zrobić w jQuery?