Ajax uses the post method to pass Parameters

Source: Internet
Author: User

. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.