var request;
var queryString;
var arryDrplst=new Array();
function sendData()
{
var postStr=document.all.文本框名字.value;
var url="../你的頁面名.aspx?name="+postStr ;
httpRequest("POST",url,true);
}
function httpRequest(reqType,url,asynch)
{
if(window.XMLHttpRequest)//如果是IE7+瀏覽器,使用內嵌XMLHttpRequest对象。
{
request = new XMLHttpRequest( );
}
else if (window.ActiveXObject)//如果是IE7版本以下的瀏覽器
{
request=new ActiveXObject("Msxml2.XMLHTTP");
if (! request)//如果對象為空
{
request=new ActiveXObject("Microsoft.XMLHTTP");
}
}
if(request)//如果對象不為空
{
initReq(reqType,url,asynch);
}
else
{
alert('錯誤信息述,你自己寫!');
}
}
function initReq(reqType,url,isAsynch)
{
request.onreadystatechange=handleResponse;//當對象只讀狀態改變的時候
request.open(reqType,url,isAsynch);
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
request.send(queryString);
}
function handleResponse()
{
if(request.readyState == 4)
{
if(request.status == 200)
{
var resp = request.responseText;
var oDoc=new ActiveXObject("MSXML2.DOMDocument");//定義XML文檔對象
oDoc.loadXML(resp);//將XML文件的內容加載到xmldom對象中
var root=oDoc.documentElement;//直接加載時獲得根節點
//
for (var i = 0; i<root.childNodes.length;i++)
{
//selectSingleNode("xxx")-->此方法會傳回第一個符合的節點對象,如果沒有符合的節點,傳回null
if (root.childNodes[i].selectSingleNode("AGE")!=null )
{
var varAGE = root.childNodes[i].selectSingleNode("AGE").text;
document.all.第二個文本框.value = varAGE;
}
}
}
}
[此贴子已经被作者于2007-6-6 8:54:19编辑过]
在Page_Load中:
If Me.Request("name") <> Nothing Then '從客戶端返回的數據
Dim strGetClientValue As String = Me.Request("name")
getAGE(strGetClientValue)
End If
Private Sub getAge(ByVal strGetClientValue As String)
Try
Dim dtPostedTable As DataTable = GetData(strGetClientValue)
'得到要傳送到客戶端的groupname要邦定的值,GetData是你自己寫的方法,用來得到一個DataTable.
Dim dsPosted As New DataSet("Person")
dsPosted.Tables.Add(dtPostedTable)
Dim strPersonReturnXml As String = "<?xml version=" + Chr(34) + "1.0" + Chr(34) + " ?> " + Chr(13) + dsPosted.GetXml() '發送到客戶端的xml
Response.Write(strPersonReturnXml )
Response.End()
Catch ex As Exception
End Try
End Sub