<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<script language="javascript" type="text/javascript">
var httpXML;
function createXMLObject()
{
if (window.ActiveXObject)
{
httpXML=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
httpXML=new XMLHttpRequest();
}
}
function startRequest()
{
createXMLObject();
var query="yourname="+ document.getElementById("txtname").value;
httpXML.onreadystatechange=handleEventStateChange;
httpXML.open("POST","postData.aspx",true);
httpXML.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")//这一句是关键,经过试验,这一句需要放在open后……
httpXML.send(query);
}
function handleEventStateChange()
{
if (httpXML.readyState==4)
{
if (httpXML.status==200)
{
//dosomething
alert(httpXML.responseText);
}
}
}
</script>
</head>
<body>
<input type="text" id="txtname" value="111" onblur="startRequest();" />
</body>
</html>
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class postData : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string requestquery = Request["yourname"].ToString();
//string requestquery=Request.Form["yourname"].ToString();
Response.Write("Welcome " + requestquery);
}
}