Traditional data submission methods are implemented using <form>.
<Form> the method attribute in the tag determines that when the data of the form element is sent to the server,
How to package HTTP request information.
Methods available for the method attribute
Request set for reading data by using the method attribute to send form elements
Get ID at the end of the URL querystring
Post form in the body of the HTTP request (free area of the HTTP request)
This articleArticleUse XMLHTTP to implement form method = post.
Clientpost.htm
<Script language = "JavaScript">
Function adddatapost (suserid, susername)
{
/*
* ------------- Adddatapost (suserid, susername )-----------------
* Adddatapost (suserid, susername)
* Function: add data through XMLHTTP. equivalent to form method = post.
* Parameter: suserid, String, sending condition.
* Parameter: susername, String, sending condition.
* Instance: adddatapost (document. All. userid. Value, document. All. username. value );
* ------------- Adddatapost (suserid, susername )-----------------
*/
VaR obao = new activexobject ("Microsoft. XMLHTTP ");
// Special characters: +, %, &, = ,? And other transmission solutions.
// Update:
// Escape (suserid), escape (susername );
Suserid = escape (suserid );
Susername = escape (susername );
VaR userinfo = "userid =" + suserid + "& username =" + susername;
Obao. Open ("Post", "server. asp", false );
Obao. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ")
Obao. Send (userinfo );
// Clear the data in the input box.
Document. All. userid. value = "";
Document. All. username. value = "";
// The server processes the returned escape encoded string.
Alert (Unescape (obao. responsetext ))
}
</SCRIPT>
<Input type = "button" onclick = "adddatapost (document. All. userid. Value, document. All. username. Value)" value = "adddatapost"> <br>
Userid: <input type = "text" name = "userid"> <br>
Username: <input type = "text" name = "username">
Server. ASP server processing.
<% @ Language = "JavaScript" %>
<%
Function opendb (sdbname)
{
/*
* --------------- Opendb (sdbname )-----------------
* Opendb (sdbname)
* Function: Open the database sdbname and return the conn object.
* Parameter: sdbname, String, database name.
* Instance: var conn = opendb ("database. mdb ");
* --------------- Opendb (sdbname )-----------------
*/
VaR connstr = "provider = Microsoft. Jet. oledb.4.0; Data Source =" + server. mappath (sdbname );
VaR conn = server. Createobject ("ADODB. Connection ");
Conn. Open (connstr );
Return conn;
}
VaR sresult = "";
VaR oconn = opendb ("data. mdb ");
// Equivalent to form method = post.
// Equivalent to form method = post.
// Special characters: +, %, &, = ,? And other transmission solutions. The client is transmitted through escape encoding.
// Therefore, Unescape decoding should be performed on the receiver first.
// Update:
// Unescape (request. Form ("userid ")).....
VaR userid = Unescape (request. Form ("userid "));
VaR username = Unescape (request. Form ("username "));
Sresult = "userid:" + userid + "\ nusername:" + username + "\ n added successfully ."
VaR SQL = "insert into users (userid, username) values ('" + userid + "', '" + username + "')";
Oconn. Execute (SQL );
Response. Write (escape (sresult ));
%>
Database Design
Data. MDB
Table users.
Field
Id automatic number
Userid text
Username text
Table: Users data:
Id userid Username
1 wanghr100 Administrator