Da questo spunto:
http://blog.html.it/archivi/2005/11/...ato-facile.php
A parte il fatto che non vedo (mah, sono miope
) quali siano le differenze con AJAX, chiedo:
Le librerie riportate negli articoli, funzionano? :master:
Ho fatto una paginetta asp con due pulsanti che fanno una richiesta server ciascuno. Ho simulato una elaborazione server di qualche secondo. Ho pigiato in sequenza i due pulsanti ed il risultato è che non vedo le due risposte nello schermo. Il codice che ho usato è:
codice:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>a</title>
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="ProgId" content="VisualStudio.HTML">
<meta name="Originator" content="Microsoft Visual Studio .NET 7.1">
<script id="clientEventHandlersJS" language="javascript">
<!--
function Button1_onclick() {
ahah("a2.asp?ahah=button1", "div1")
}
function Button2_onclick() {
ahah("a2.asp?ahah=button2", "div2")
}
/*----------------------------------LIBRERIA AHAH----------------------------------------------*/
function ahah(url,target) {
// native XMLHttpRequest object
document.getElementById(target).innerHTML = 'sending...';
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = function() {ahahDone(target);};
req.open("GET", url, true);
req.send(null);
// IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = function() {ahahDone(target);};
req.open("GET", url, true);
req.send();
}
}
}
function ahahDone(target) {
// only if req is "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200 || req.status == 304) {
results = req.responseText;
document.getElementById(target).innerHTML = results;
} else {
document.getElementById(target).innerHTML="ahah error:\n" + req.statusText;
}
}
}
var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
var bOpera = (navigator.userAgent.indexOf('Opera') != -1);
var bMoz = (navigator.appName == 'Netscape');
function execJS(node) {
var st = node.getElementsByTagName('SCRIPT');
var strExec;
for(var i=0;i<st.length; i++) {
if (bSaf) {
strExec = st[i].innerHTML;
}
else if (bOpera) {
strExec = st[i].text;
}
else if (bMoz) {
strExec = st[i].textContent;
}
else {
strExec = st[i].text;
}
try {
eval(strExec);
} catch(e) {
alert(e);
}
}
}
/*----------------------------------LIBRERIA AHAH----------------------------------------------*/
//-->
</script>
</head>
<body MS_POSITIONING="FlowLayout">
<INPUT type="button" value="Button1" ID="Button1" NAME="Button1" language="javascript" onclick="return Button1_onclick()">
<INPUT type="button" value="Button2" ID="Button2" NAME="Button2" language="javascript" onclick="return Button2_onclick()">
<div id="div1"></div>
<div id="div2"></div>
</body>
</html>
<%
dim a, b, i
a = trim(Request.QueryString("ahah"))
select case a
case "button1"
response.Clear
a = "": for i=1 to 10000:a = a & "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx":next
response.Write("valore restituito da button1" & "<script>alert('codice button1');</script>")
response.End
case "button2"
response.Clear
a = "": for i=1 to 10000:a = a & "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx":next
response.Write("valore restituito da button2" & "<script>alert('codice button2');</script>")
response.End
end select
%>