1.客户端部分
<script language="javascript" type="text/javascript">
var xhr=null;
//创建XMLHTTPRequest
function getXHR()
{
var _xhr=null;
if(window.ActiveXObject)
{
_xhr=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
_xhr=new XMLHttpRequest();
}
return _xhr;
}
function sendRequest()
{
if(xhr!=null)
{
xhr.onreadystatechange=getResult;
xhr.open("Get","url",true);
xhr.send("goyier");
}
}
function getResult()
{
if(xhr.readyState==4)
{
if(xhr.status==200)
{
alert(xhr.responseText);
}
}
}
</script>
<input type="button" name="send" value="发送请求(Get)" onclick="sendRequest();"></input>
//Server端部分
protected void Page_Load(object sender,EventAgrs e)
{
Response.Clear();
Response.OutPut.Write("Hello!"+getRequestParams());
Response.End();
}
public string getRequestParams()
{
Stream paramsStream=Request.InputSteam;
byte[] resultByte=new byte[paramsStream.Length];
paramsStream.Read(resultByte,0,paramsStream.Length-1);
Encoding encode = Encoding.UTF8;
return encode.GetString(resultByte);
}
//调用结果:
Hello! goyier