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.