Asp:get Request notation

Source: Internet
Author: User

Write it in front.

The first argument to the XMLHttpRequest object's Open method is Request-type, and the value can be get or post. This article describes get requests.

The purpose of a GET request is primarily to obtain data. Although a GET request can pass data, the purpose of passing the data is to tell the server what content to give us.

When a GET request is used, the parameters are passed with the URL.

When using get requests, it is easy to be cached and be aware of caching issues.

When using a GET request, use Request.querystring[data] on the server side to get the data.

The problem found

We used the GET request in the full Ajax instance article, when we encountered the following problem:

  1. How to create a XMLHttpRequest object that can run in most browsers.
  2. There is a cache problem with get requests
  3. Chinese garbled problem

Among them, the first question, in the article "XMLHttpRequest object" has been resolved;

For the second problem, the reason is:

A GET request accesses the cache every time, to see if there is a matching URL, and if so, returns the URL in the cache and, if not, makes a request to the server.

Solution:

1. Add a dynamic change parameter to the URL in order to each access a different URL, so that each time a new request is made to the server.

For the third problem, we first look at the cause of garbled:

XMLHTTP the data returned by default is Uft-8, if the client page is gb2312 or other encoding, it will produce garbled

Solution:

1. If the client is gb2312, specify the output stream encoding at the time of output

2. Utf-8 encoding is used on both the client and server side

3. Be sure to encode the parameters using the encodeURIComponent method

Take a look at the example:

Example

The page HTML file does not change, the knowledge of the change JS code, the code is as follows:

 <script type= "Text/javascript" > Function Btn_click () {//Create XMLHttpRequest object var xmlHttp = Windo W.xmlhttprequest?       New XMLHttpRequest (): New ActiveXObject ("Microsoft.XMLHTTP");       Gets the value var username = document.getElementById ("Txt_username"). Value;       var age = document.getElementById ("Txt_age"). Value;        Configure the XMLHttpRequest object //Use the encodeURIComponent method to encode//add parameters to the obtained parameters in order to access different URLs each time to avoid caching problems   Xmlhttp.open ("Get", "get.aspx?username=" + encodeuricomponent (username) + "&age=" + encodeuricomponent (age)       + "&random=" + math.random ()); Set callback function Xmlhttp.onreadystatechange = function () {if (xmlhttp.readystate = = 4 && xmlhttp.statu            s = =) {document.getElementById ("result"). InnerHTML = Xmlhttp.responsetext;    }}//Send the request because the parameters are in the URL, so null xmlhttp.send (NULL) is sent here; }</script> 

Server-side:

protected void Page_Load (object sender, EventArgs e) {    response.clear ();    String username = request.querystring["username"];    String age = request.querystring["age"];    Response.Write ("Name: '" + username + "' <br/> Age:" + ages + "<br/> time: '" + DateTime.Now.ToString () + "'");    Response.End ();}




From http://www.cnblogs.com/oneword/archive/2011/06/04/2072585.html

Asp:get Request notation

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.