How to write the entry code for ajax
In this issue, the editor will bring you about how to write the entry code for ajax. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Static page
The code is as follows:
Untitled page
/ / you can't use it here
/ *
EncodeURI method
Encode the parameters passed by URL
Encodes the text string into a valid uniform resource identifier (URI).
, /
Function createQueryString () {
Var firstName=encodeURI ($("# firstName") .val ())
Var birthday=encodeURI ($("# birthday") .val ())
/ / combined into the form of an object
Var queryString= {firstName:firstName,birthday:birthday}
Return queryString
}
Function doRequestUsingGET () {
Get ("AjaxServe.aspx", createQueryString ()
/ / send GET request
Function (data) {
$("# serverResponse") .html (decodeURI (data))
}
);
}
Function doRequestUsingPOST () {
$.post ("AjaxServe.aspx", createQueryString ()
/ / send POST request
Function (data) {
$("# serverResponse") .html (decodeURI (data))
}
);
}
Enter name and birthday
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"])
}
The above is the editor for you to share the ajax entry code how to write, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.