Grazie !
Quello che voglio fare io è una chat Asp + Ajax:
Sono a buon punto credo, ma pultroppo la parte Ajax non fa per me
mi puoi per favore correggere-ottimizzare il js di questa pagina ?
grazie !
codice:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SuperChat v. 1.0</title>
<script type="text/javascript">
var xmlHttp
var url
var rnd = Math.random();
window.setInterval('aggiorna()',2000);
// - - - - - - - - - - - - - - - - - -
function aggiorna() {
messaggi();
utenti();
}
// - - - - - - - - - - - - - - - - - -
function messaggi() {
rnd++;
url = "messaggi.asp?r" + rnd;
xmlHttp=GetXmlHttpObject()
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
obj = document.getElementById("messaggi");
obj.innerHTML = xmlHttp.responseText
}
}
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
}
function utenti() {
rnd++;
url = "utenti.asp?r" + rnd;
req = GetXmlHttpObject()
req.onreadystatechange = function() {
if( req.readyState == 4 && req.status == 200 ) {
obj = document.getElementById( "utenti" );
obj.innerHTML = req.responseText;
}
}
req.open( 'GET', url, true );
req.send( null );
}
function chatta(v) {
v.disabled = true;
objHTTP = GetXmlHttpObject()
parametri = "msg=" + escape(v.value);
url = "add.asp?msg=" + escape(v.value);
objHTTP.open("POST", url, true);
objHTTP.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
objHTTP.setRequestHeader('Content-length',parametri.length);
objHTTP.setRequestHeader('Connection', 'close');
objHTTP.send(parametri);
v.disabled = false;
}
// - - - - - - - - - - - - - - - - - -
function GetXmlHttpObject() {
var objXmlHttp = null
if (window.XMLHttpRequest) {
objXmlHttp = new XMLHttpRequest();
} else {
objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
// - - - - - - - - - - - - - - - - - -
try {
return objXmlHttp
} catch (e) {
alert("Errore !")
return
}
}
</script>
</head>
<body>
<div id="contenitore">
<div id="testata">
<h1>SuperChat v. 1.0</h1>
</div>
<div id="chat">
<div id="messaggi">
Qua i messaggi</p>
</div>
<div id="utenti">
Qua gli utenti</p>
</div>
<div id="editor">
<form id="form1" action="?">
<input name="regioni" type="text" id="regioni" /></p>
<input type="submit" onclick="chatta(this);" value="Invia" /></p>
</form>
</div>
</div>
</div>
</body>
</html>