Using XMLHTTP without refreshing to add data to get articles

Source: Internet
Author: User
xml| Data | refresh | no refresh

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);
*---------------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.
Alert (unescape (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");
*---------------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=get.
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 Administrator



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.