Differences between AJAX and post modes: ajaxgetpost Mode

Source: Internet
Author: User

Differences between AJAX and post modes: ajaxgetpost Mode

This article analyzes the differences between AJAX and post modes. Share it with you for your reference. The specific analysis is as follows:

If the request is in get mode, the transmitted parameters are sent to the server through the URL address;

For post requests, the transmission parameters are sent to the server through the send () method (and the request file header must be set );

The post mode code 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 used to send data // --> </script>

An example of the difference between get mode and post mode:

Client:

Sample Code:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <Html> 

Server

Sample Code:
Copy codeThe Code is 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"]);
%>

Requests in get mode are usually used when there is not much data and are not sensitive;

When there is a large amount of data or the data is sensitive, post-mode requests are used.

I hope this article will help you with 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.