Ajax instance Entry Code _ajax related

Source: Internet
Author: User

Static page

Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Untitled Page </title>
<script type= "Text/javascript" src= "Jquery/jquery.js" >
You can't use <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 ());
Grouped into the form of an object
var querystring={firstname:firstname,birthday:birthday};
return querystring;
}
function Dorequestusingget () {
$.get ("Ajaxserve.aspx", createquerystring (),
Send a GET request
function (data) {
$ ("#serverResponse"). HTML (decodeURI (data));
}
);
}
function Dorequestusingpost () {
$.post ("Ajaxserve.aspx", createquerystring (),
Send POST request
function (data) {
$ ("#serverResponse"). HTML (decodeURI (data));
}
);
}
</script>
<body>
<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>


Dynamic page
Copy Code code 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"]);
}

Related Article

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.