xml| Data | refresh | no refresh
Use XMLHTTP no refresh to add the data to the Get article.
The first two articles are mainly written from getting data. Next, let's talk about how to add data.
Our traditional methods of submitting data are implemented by <Form>.
The method property in the <Form> tag determines that the data for the form element is sent to the server
How to package HTTP request information.
Method property can be used
Method property to send form elements to read the request collection of data
Get identity at the end of URL querystring
Post in the body of the HTTP request (the free area of the HTTP request) Form
This article uses XMLHTTP to realize the form's method=get.
Clientget.htm
<script language= "JavaScript" >
function Adddataget (suserid,susername)
{
/*
*---------------Adddataget (suserid,susername)-----------------
* Adddataget (Suserid,susername)
* Function: Add data through XMLHTTP. Equivalent to the form of the method=get.
* Parameter: sUserID, string, send condition.
* Parameter: sUserName, string, send condition.
* Example: Adddataget (Document.all.userid.value,document.all.username.value);
* AUTHOR:WANGHR100 (Grey bean baby. NET)
* Update:2004-5-30 14:46
*---------------Adddataget (suserid,susername)-----------------
*/
var Obao = new ActiveXObject ("Microsoft.XMLHTTP");
Special characters: +,%,&,=, etc. transmission solutions. Use escape code.
Update:2004-6-1 12:22
Escape (sUserID), Escape (sUserName);
Obao.open ("POST", "server.asp?userid=" +escape (sUserID) + "&username=" +escape (sUserName), false);
Obao.send ();
//Empty the input box data.
Document.all.userid.value= "";
Document.all.username.value= "";
//server-side processing returns a string that is encoded by escape.
Alertunescape (Obao.responsetext))
}
</script>
<input type= "button" value= "Adddataget" ><br>
Userid:<input type= "text" name= "userid" ><br>
Username:<input type= "text" name= "username" >
Server.asp server-side processing.
<% @Language = "JavaScript"%>
<%
function Opendb (sdbname)
{
/*
*---------------opendb (sdbname)-----------------
* OPENDB (Sdbname)
* Function: Open database Sdbname, return conn object.
* Parameters: Sdbname, String, database name.
* Example: var conn = opendb ("Database.mdb");
* AUTHOR:WANGHR100 (Grey bean baby. NET)
* Update:2004-5-12 8:18
*---------------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 the method=get of form.
Equivalent to the form of the method=get.
Special characters: +,%,&,=, etc. transmission solutions. The client is transmitted over the escape code.
So the end of the receiver should be decoded first with unescape.
Update:2004-6-1 12:22
Unescape (Request.QueryString ("userid")) ...
var userid = unescape (Request.QueryString ("userid"));
var username = unescape (request.querystring ("username"));
Sresult = "UserID: +userid+" \nusername: "+username+" \ n Add success. "
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 Auto Number
UserID text
Username text
Table: Users data:
ID userid Username
1 wanghr100 baby grey peas. Net
using XMLHTTP to add data without refreshing
Let's talk about how to add data.
Our traditional methods of submitting data are implemented by <Form>.
The method property in the <Form> tag determines that the data for the form element is sent to the server
How to package HTTP request information.
Method property can be used
Method property to send form elements to read the request collection of data
Get identity at the end of URL querystring
Post in the body of the HTTP request (the free area of the HTTP request) Form
This article takes the Post method as an example, the Get method is simpler
--------------------------------------------------------------------------------------------------------------- -------------
This article uses XMLHTTP to realize the form's method=post.
Clientpost.htm
<script language= "JavaScript" >
function Adddatapost (suserid,susername)
{
/*
*---------------Adddatapost (suserid,susername)-----------------
* Adddatapost (Suserid,susername)
* Function: Add data through XMLHTTP. Equivalent to the form of the method=post.
* Parameter: sUserID, string, send condition.
* Parameter: sUserName, string, send condition.
* Example: Adddatapost (Document.all.userid.value,document.all.username.value);
* AUTHOR:WANGHR100 (Grey bean baby. NET)
* Update:2004-5-30 14:46
*---------------Adddatapost (suserid,susername)-----------------
*/
var Obao = new ActiveXObject ("Microsoft.XMLHTTP");
Special characters: +,%,&,=, etc. transmission solutions.
Update:2004-6-1 12:22
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);
Empty the input box data.
Document.all.userid.value= "";
Document.all.username.value= "";
Server-side processing returns a string that is encoded by escape.
Alert (unescape (Obao.responsetext))
}
</script>
<input type= "button" value= "Adddatapost" ><br>
Userid:<input type= "text" name= "userid" ><br>
Username:<input type= "text" name= "username" >
Server.asp server-side processing.
<% @Language = "JavaScript"%>
<%
function Opendb (sdbname)
{
/*
*---------------opendb (sdbname)-----------------
* OPENDB (Sdbname)
* Function: Open database Sdbname, return conn object.
* Parameters: Sdbname, String, database name.
* Example: var conn = opendb ("Database.mdb");
* AUTHOR:WANGHR100 (Grey bean baby. NET)
* Update:2004-5-12 8:18
*---------------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 the form of the method=post.
Equivalent to the form of the method=post.
Special characters: +,%,&,=, etc. transmission solutions. The client is transmitted over the escape code.
So the end of the receiver should be unescape decoding first.
Update:2004-6-1 12:22
Unescape (Request.Form ("userid")) ...
var UserID = unescape (Request.Form ("userid"));
var username = unescape (Request.Form ("username"));
Sresult = "UserID: +userid+" \nusername: "+username+" \ n Add success. "
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 Auto Number
UserID text
Username text
Table: Users data:
ID userid Username
1 wanghr100 baby grey peas. Net