In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to use the ASP+AJAX+ACCESS database. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
The basic application of AJAX+ASP will be explained in three steps, as follows.
1. The creation of foreground AJAX code (javascript).
two。 Background server ASP AJAX code writing.
3. An example demonstration and explanation of ASP+AJAX+ database.
The first step: the creation of foreground AJAX code (javascript).
Let's first create an index.html foreground file with the following code:
The copy code is as follows:
AJAX tutorial example-AJAX tutorial example-ASP+AJAX+ACCESS database application-original ajax example tutorial
Var xmlHttp
Function showCustomer (str)
{
Var url= "getcustomer.asp?sid=" + Math.random () + "& Q =" + str
XmlHttp=GetXmlHttpObject (stateChanged)
XmlHttp.open ("GET", url, true)
XmlHttp.send (null)
}
Function stateChanged ()
{
If (xmlHttp.readyState==4 | | xmlHttp.readyState== "complete")
{
Document.getElementById ("txtHint") [xss_clean] = xmlHttp.responseText
}
}
Function GetXmlHttpObject (handler)
{
Var objXmlHttp=null
If (navigator.userAgent.indexOf ("Opera") > = 0)
{
Alert ("This example doesn't work in Opera")
Return
}
If (navigator.userAgent.indexOf ("MSIE") > = 0)
{
Var strName= "Msxml2.XMLHTTP"
If (navigator.appVersion.indexOf ("MSIE 5.5") > = 0)
{
StrName= "Microsoft.XMLHTTP"
}
Try
{
ObjXmlHttp=new ActiveXObject (strName)
ObjXmlHttp.onreadystatechange=handler
Return objXmlHttp
}
Catch (e)
{
Alert ("Error. Scripting for ActiveX might be disabled")
Return
}
}
If (navigator.userAgent.indexOf ("Mozilla") > = 0)
{
ObjXmlHttp=new XMLHttpRequest ()
ObjXmlHttp.onload=handler
ObjXmlHttp.onerror=handler
Return objXmlHttp
}
}
Please select a user:
The principle of this line of code is to trigger the foreground script object of AJAX through showCustomer (this.value), send the result data selected by the user in the drop-down list to the server for processing through Microsoft.XMLHTTP, and then return to the user information whose foreground ID is txtHint. The layer label is displayed.
The second step: writing the ASP AJAX code of the server in the background.
After creating the index.html just now, we then create another getcustomer.asp file. Please confirm everything in your ASP environment OK:)
The code for getcustomer.asp is as follows:
The copy code is as follows:
Ajax code explanation:
If friends with asp foundation can understand at a glance, connect to the database code and query the corresponding database results according to the Q parameters sent by the front desk:
The copy code is as follows:
Sql= "SELECT * FROM CUSTOMERS WHERE CUSTOMERID="
Sql=sql & request.querystring ("Q")
Set conn=Server.CreateObject ("ADODB.Connection")
Conn.Provider= "Microsoft.Jet.OLEDB.4.0"
Conn.Open (Server.Mappath ("ajaxjiaocheng.mdb"))
Set rs = Server.CreateObject ("ADODB.recordset")
Rs.Open sql, conn
The next thing to notice is this line of code:
The sentence Response.CharSet = "GB2312" is very important to solve the garbled code in ajax.
In the process of using AJAX, many people often encounter the problem that Chinese display in ajax becomes garbled. In fact, it is easy to solve this problem in ASP+AJAX application. Just add this line of code before the output of Chinese content in Response.Write statement, and you can easily solve the problem of Chinese garbled in ajax.
Continue to explain the following code, which is to display the corresponding database query results and close the database connection:
The copy code is as follows:
If not rs.EOF then
Response.write "No.:" & rs (0) & ""
Response.write "name: & rs (1) &"
Response.write "Click:" & rs (2) & "
Introduction to response.write: & rs (3) & "
End if
Rs.close
Set rs = nothing
Conn.close
Set conn = nothing
Step 3: demonstration and explanation of ASP+AJAX+ database
Along the way, the code is very concise and clear. Below, we attach the description of the database table as follows:
Library name: ajaxjiaocheng.mdb
Table name: Customers
Field 1:CustomerID automatic numbering
Field 2:Name text format
Field 3:NL number format
Field 4:Address text format
Seeing here, I wonder if you can understand how AJAX works. It is recommended that you follow this tutorial step by step to write code and test it.
Intuitively, this example can be understood as follows:
Through the index.html page
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.