小弟最近新学Ajax,遇到这么个问题。假设小弟的Html代码是这样:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Sending Request Data Using GET and POST</title>
<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 language="javascript">
var xmlHttp;function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(windo.HTMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}function createQueryString()
{
var firstName = document.getElementById("firstName").value;
var middleName = document.getElementById("middleName").value;
var birthday = document.getElementById("birthday").value;

var queryString = "firstname=" + firstName + "&middlename=" + middleName + "&birthday=" + birthday;
return queryString;
}function doRequestUsingGET()
{
createXMLHttpRequest();

var queryString = "WebForm3.aspx?";
queryString = queryString + createQueryString() + "&timeStamp=" + new Date().getTime();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET",queryString, true);
xmlHttp.send(null);
}function doRequestUsingPOST()
{
createXMLHttpRequest();

var url = "WebForm3.aspx?timeStamp=" + new Date().getTime();
var queryString = createQueryString();

xmlHttp.open("POST", url, true);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
xmlHttp.send(queryString);
}function handleStateChange()
{
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
parseResult();
}
}
}function parseResult()
{
var responseDiv = document.getElementById("serverResponse");
if(responseDiv.hasChildNodes())
{
responseDiv.removeChild(responseDiv.childNodes[0]);
}
var responseText = document.createTextNode(xmlHttp.responseText);
responseDiv.appendChild(responseText);
}
</script>
</head>
<body>
<h1>Enter your first name, middle name, and birthday:</h1>

<table>
<tr>
<td>First Name:</td>
<td><input type="text" id="firstName"></td>
</tr>
<tr>
<td>Middle Name:</td>
<td><input type="text" id="middleName"></td>
</tr>
<tr>
<td>Birthday:</td>
<td><input type="text" id="birthday"></td>
</tr>
</table>

<form action="#">
<input type="button" value="Send parameters using GET" onclick="doRequestUsingGET();">
<br><br>
<input type="button" value="Send parameters using POST" onclick="doRequestUsingPOST();">
<br>
<h2>Server Response:</h2>
<div id="serverResponse"></div>
</form>
</body>
</html>
服务器端WebForm3.aspx没有HTML代码,.cs代码如下:private void Page_Load(object sender, System.EventArgs e)
{
Response.ContentType = "text/xml"; string firstName = Request.QueryString["firstname"] != "" ? Request.QueryString["firstname"].ToString() : "";
string middleName = Request.QueryString["middlename"] != "" ? Request.QueryString["middlename"].ToString() : "";
string birthday = Request.QueryString["birthday"] != "" ? Request.QueryString["birthday"].ToString() : "";
string returnValue = "FirstName:" + firstName + ",MiddleName:" + middleName + ",Birthday:"+birthday; Response.Write(returnValue);
Response.Flush();
Response.Close();
}
这是我根据某教科书上的例子改的,目的就是在HTML中输入姓名、生日等信息,经过服务器端拼成一个字符穿再返回给前台。不过目前小弟使用GET的方式没有问题,但是使用POST好象不行。书上的例子是JAVA的,因此小弟想请教各位高手,对于POST形式的请求应该怎么解释参数?用什么方式?还请各位不吝赐教,因为这关系到XML请求的问题,所以目前小弟卡在这里了,不胜感激!

解决方案 »

  1.   

    看的是ajax foundation吧,呵呵.
      

  2.   

    汗,谢谢2楼,确实是Request.Params["参数名"],小弟浅薄了。
    另TO 3楼:确实是ajax   foundation,手边也确实借不到什么更好的教材了,这个经典啊^_^ 项目时间紧,BOSS还极度不喜欢用Ajax控件,只能自己动手了,不过也确实挺有意思。
      

  3.   

     asp.net AJAX 技术交流群   1927901  欢迎加入 ,长期不参与讨论者勿进