. Aspx code
<HTML>
<Head>
<SCRIPT type = "text/JavaScript">
Function loadxmldoc ()
{
VaR XMLHTTP;
If (window. XMLHttpRequest) // code for IE7 +, Firefox, chrome, opera, Safari
{
XMLHTTP = new XMLHttpRequest ();
}
Else // code for IE6, ie5
{
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
XMLHTTP. onreadystatechange = function ()
{
If (XMLHTTP. readystate = 4 & XMLHTTP. Status = 200)
{
Document. getelementbyid ("divresponse"). innerhtml = XMLHTTP. responsetext;
}
}
XMLHTTP. Open ("Post", "post. aspx", true );
XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
XMLHTTP. Send ("Param = test ");
}
</SCRIPT>
</Head>
<Body>
<H2> Ajax uses the post method to pass Parameters </H2>
<Button type = "button" onclick = "loadxmldoc ()"> click </button>
<Div id = "divresponse"> </div>
</Body>
</Html>
. CS code
Public partial class post: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
If (request. Form ["Param"]! = NULL)
{
String username = request. Form ["Param"]. tostring ();
Response. Write ("the parameter is:" + PARAM );
Response. End ();
}
}
}
How to Get parameters:
Request. querystring ["Param"] -- get Method
Request. Form ["Param"] -- Post Method