Ajax uses get vs. Post mode difference Analysis _ajax correlation

Source: Internet
Author: User

This article analyzes the difference between using GET and post mode for Ajax. Share to everyone for your reference. The specific analysis is as follows:

If the request is a get mode, the pass parameter is sent to the server side via the URL address;

If the request is in post mode, the pass parameter is sent through the Send () method to the server side (and the request file header must be set);

The code for Post mode is as follows:

<script type= "Text/javascript" >
<!--
var querystring = "firstname=xugang&birthday=1227";
var url = "9-3.aspx?timetamp=" + New Date (). GetTime ();
Xmlhttp.open ("POST", url);
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xmlhttp.send (querystring); This statement is responsible for sending data
//-->
</script>

An example that demonstrates the difference between get mode and post mode:

Client:

code example:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

Server-side

code example:

Copy Code code as follows:
<%@ Page language= "C #" contenttype= "text/html" responseencoding= "gb2312"%>
<%@ Import namespace= "System.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"]);
%>

A request that uses the Get mode usually when the data is not much and is not sensitive;

When the data is large, or the data is sensitive, use the Post mode request.

I hope this article will help you with your AJAX programming.

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.