Ciao.
Ho questo semplice script che
serve per recuperare una pagina
php con una query.
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript" type="text/javascript">
var time = 2000;
var page = "query.php";
//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
var receiveReq=false; //Clear our fetching variable
try {
receiveReq = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
} catch (e) {
try {
receiveReq = new ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
} catch (e) {
receiveReq = false;
}
}
if (!receiveReq && typeof XMLHttpRequest!='undefined') {
receiveReq = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
}
return receiveReq;
}
//Get our browser specific XmlHttpRequest object.
var receiveReq = getXmlHttpRequestObject();
//Initiate the asyncronous request.
function getQuery() {
//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
//Setup the connection as a GET call to SayHello.html.
//True explicity sets the request to asyncronous (default).
receiveReq.open('GET', page , true);
//Set the function that will be called when the XmlHttpRequest objects state changes.
receiveReq.onreadystatechange = handlegetQuery;
//Make the actual request.
receiveReq.send(null);
alert("Sono ingetQuery");
setTimeout('getQuery()',time);
}
}
//Called every time our XmlHttpRequest objects state changes.
function handlegetQuery() {
//Check to see if the XmlHttpRequests state is finished.
alert("Sono in handlegetQuery");
if (receiveReq.readyState == 4) {
//Set the contents of our span element to the result of the asyncronous call.
var content = receiveReq.responseText;
document.getElementById('news').innerHTML = content;
}
}
window.onload = function()
{
getQuery();
}
</script>
</head>
<body>
<p id="news"></p>
</body>
</html>
Il risultato della query lo
recupera senza battere ciglio.
Il problema è che vorrei non so
ad un nuovo inserimento o update
del Db vedere l'aggiornamento senza
fare il refresh della pagina per questo
ho provato ad utiizzare setTimeout ma
non funziona dov'è che sbaglio ?
Ps.
Per la cronaca vince handlegetQuery 3-1
Dato che ci siamo se mi spiegate anche questa
mi immagino che sia per i vari stati readyState
ma vorrei conferma o smentita