Static Page
The Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> No title page </title>
<Script type = "text/javascript" src = "jquery/jquery. js">
// <Script type = "" src = "/>
</Script>
<Script type = "text/javascript">
/*
EncodeURI Method
Encode the parameters passed by the URL
Encodes a text string into a valid Uniform Resource Identifier (URI ).
*/
Function createQueryString (){
Var firstName = encodeURI ($ ("# firstName"). val ());
Var birthday = encodeURI ($ ("# birthday"). val ());
// Combine them into objects
Var queryString = {firstName: firstName, birthday: birthday };
Return queryString;
}
Function doRequestUsingGET (){
$. Get ("AjaxServe. aspx", createQueryString (),
// Send a GET request
Function (data ){
$ ("# ServerResponse" pai.html (decodeURI (data ));
}
);
}
Function doRequestUsingPOST (){
$. Post ("AjaxServe. aspx", createQueryString (),
// Send a POST request
Function (data ){
$ ("# ServerResponse" pai.html (decodeURI (data ));
}
);
}
</Script>
</Head>
<Body>
<H2> enter name and birthday <Form>
<Input type = "text" id = "firstName"/> <br/>
<Input type = "text" id = "birthday"/>
<Input type = "button" value = "GET" onclick = "doRequestUsingGET ();"/> <br/>
<Input type = "button" value = "POST" onclick = "doRequestUsingPOST ();"/>
</Form>
<Div id = "serverResponse"> </div>
</Body>
</Html>
Dynamic page
The Code is as follows:
Protected void Page_Load (object sender, EventArgs e)
{
// Response. Write ("background data ");
If (Request. HttpMethod = "POST ")
Response. Write ("POST:" + Request ["firstName"] + ", your birthday is" + Request ["birthday"]);
Else if (Request. HttpMethod = "GET ")
Response. Write ("GET:" + Request ["firstName"] + ", your birthday is" + Request ["birthday"]);
}