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.