Perchè cercare o farsi da soli funzioni che già esistono in rete e che oltretutto funzionano magnificamente bene? :master:
Ti faccio un esempio commentato che fa uso di jquery e asp.
In pratica spedisco dei valori via get e post. Il server gli legge e li rispedisce al client
codice:
<%
option explicit
Response.Buffer = true
Session.LCID = 1040
onLoad
%>
<!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></title>
<script type="text/javascript" src="../js/jquery/jquery-1.3.2.min.js"></script>
<script language="javascript" type="text/javascript">
// <!CDATA[
function fai_richiesta_ajax_post()
{
//faccio comparire l'indicatore di attesa
$('#div1').html('[img]../immagini/indicator.white.gif[/img]');
//imposto la pagina da richiamare
//richiamo pagina corrente e mando pure il parametro per dire al server cosa fare
var url = "?parametro_ajax=1";
//i dati da spedire sono tutti quelli di form1 più variabile1 di valore1
var dati = $("#form1").serialize() + "&" + "variabile1=valore1";
//faccio la richiesta ajax al server specificando l'url da richiamare, i dati da spedire,
//il modo di spedizione, la procedura da eseguire in caso di successo,
//la procedura da eseguere in caso di errore
$.ajax({url:url, data:dati, type: 'post', success:callback, error:onerror});
//procedura eseguita in caso di successo
function callback(data, textStatus)
{
//metto l'html ricevuto in div1
$("#div1").html(data);
}
//procedura eseguita in caso di errore
function onerror(XMLHttpRequest, textStatus, errorThrown)
{
//cancello il contenuto di div1 e alert di errore
$('#div1').html("");
alert("Errore richiesta ajax");
}
}
// ]]>
</script>
</head>
<body>
<form id="form1" action="?">
Fai la richiesta POST
<hr />
<input id="Text1" name="Text1" type="text" value="xyz" />
<input id="Hidden1" name="Hidden1" type="hidden" value="abx" />
<hr />
<div id="div1" style="border:4px red solid; width:500px; height:500px; padding:10px;"></div>
</form>
</body>
</html>
<%
sub onLoad()
dim parametro_ajax
parametro_ajax = trim(request.QueryString("parametro_ajax"))
if parametro_ajax = "1" then
esegui_procedura_1()
end if
end sub
sub esegui_procedura_1()
ScriviParametri
response.End
end sub
%>
<%
'--------------------------------------------------------------
'scrive i parametri passati come post
'--------------------------------------------------------------
sub ScriviParametriForm
dim f
if Request.Form.Count > 0 then
Response.Write "<span style='FONT-FAMILY: Verdana, Arial;FONT-STYLE: normal;FONT-WEIGHT: bolder;COLOR: BROWN;FONT-SIZE: 8pt;BACKGROUND-COLOR: white;'>Parametri Form</span>"
Response.Write "<table BORDER=1 CELLSPACING=0 CELLPADDING=0 bordercolor='#000000' style='FONT-FAMILY: Verdana, Arial;FONT-STYLE: normal;COLOR: #000000;FONT-SIZE: 10pt;BORDER: black thin none;background:beige;width:0;'>"
for each f in Request.Form
Response.Write "<tr><td style='PADDING-LEFT:5px;PADDING-RIGHT: 5px;PADDING-TOP: 2px;PADDING-BOTTOM: 2px;'>" & f & "</td>" & "<td style='PADDING-LEFT:5px;PADDING-RIGHT: 5px;PADDING-TOP: 2px;PADDING-BOTTOM: 2px;'>" & NullToSpace(Request.Form(f)) & "</td></tr>"
next
Response.Write "</table>"
end if
end sub
'--------------------------------------------------------------
'scrive i parametri passati come get
'--------------------------------------------------------------
sub ScriviParametriQueryString
dim f
if Request.QueryString.Count > 0 then
Response.Write "<span style='FONT-FAMILY: Verdana, Arial;FONT-STYLE: normal;FONT-WEIGHT: bolder;COLOR: BROWN;FONT-SIZE: 8pt;BACKGROUND-COLOR: white;'>Parametri QueryString</span>"
Response.Write "<table BORDER=1 CELLSPACING=0 CELLPADDING=0 bordercolor='#000000' style='FONT-FAMILY: Verdana, Arial;FONT-STYLE: normal;COLOR: #000000;FONT-SIZE: 10pt;BORDER: black thin none;background:beige;width:0;'>"
for each f in Request.QueryString
Response.Write "<tr><td style='PADDING-LEFT:5px;PADDING-RIGHT: 5px;PADDING-TOP: 2px;PADDING-BOTTOM: 2px;'>" & f & "</td>" & "<td style='PADDING-LEFT:5px;PADDING-RIGHT: 5px;PADDING-TOP: 2px;PADDING-BOTTOM: 2px;'>" & NullToSpace(Request.QueryString(f)) & "</td></tr>"
next
Response.Write "</table>"
end if
end sub
'--------------------------------------------------------------
'scrive i parametri passati form, querystring e cookies
'--------------------------------------------------------------
sub ScriviParametri()
ScriviParametriForm
ScriviParametriQueryString
end sub
'--------------------------------------------------------------
'converte NULL in spazio codificato
'--------------------------------------------------------------
function NullToSpace(v)
if isNull(v) then
NullToSpace = ""
else
if v = "" then
NullToSpace = ""
else
NullToSpace = server.HTMLEncode( v )
end if
end if
end function
%>