We will encounter many problems we don’t understand in our studies. At this time, we need to explore ourselves and find information, but the knowledge we need may not be available on the Internet. Today, the editor of Wuxin Technology Channel has compiled a summary of the grammar of js+asp for you, hoping it can help you!
Syntax summary: JS statements must be added at the end of the end of the sentence;
To write SQL statements, change the & number in VBS to + number.
In JS, single sentence comment is //, the whole paragraph is /* Here is the code to be commented*/,
The variable declaration is a var keyword, you don't need to write Set, just var directly,
The first letter of the ASP object must be capitalized, such as the S version of the Server must be capitalized, otherwise an error will be reported.
Some code differences
Connect to the database
VBS:
<%
dim conn
dim dbpath
dim connstr
Set conn =Server.CreateObject("adodb.connection")
dbpath=Server.MapPath("data.mdb")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&dbpath
conn.open connstr
%>
JS:
<%
var conn;
var dbpath;
var connstr;
conn=Server.CreateObject("adodb.connection");
dbpath=Server.MapPath("data.mdb");
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+dbpath;
conn.open(connstr);
%>
Close the connection
VBS:
<%'Close Release Record Set
rs.close
set rs = Nothing
conn.close
set conn = Nothing
%>
JS:
<%//Close Release Record Set
rs.close;
rs = null;
conn.close;
conn = null;
%>
Output
VBS:
Response.write "<script language='javascript'>alert('The operation is successful, please wait for the administrator to confirm //click to confirm to close the window');self.opener.location.reload();window.close();</script>"
JS:
Response.write("<script language='javascript'>alert('The operation is successful, please wait for the administrator to confirm //click to confirm to close the window');self.opener.location.reload();window.close();</script>");
Get the form object
VBS:
dim id
id = Request.QueryString("id")
JS:
var id = Request.QueryString("id").item;//Important, Request.QueryString in js is an object, and it needs to be added to the Item
SQL statement date query, this is too different from VBS. I was depressed for a long time and searched online for a long time before I came up with the following statement (this one is written only in JS, but I really can't write in VBS)
<%
var rs,sql;
rs = Server.CreateObject("adodb.recordset");
sql = "select * from [count] order by dae desc"
rs.open(sql,conn,1,1)
//Total visits are realized
var rst = Server.CreateObject("adodb.recordset");
sqlt="select sum(count) as dt from [count]";
rst.open(sqlt,conn,1,1);
//Implement the number of visits on the day
var rsd = Server.CreateObject("adodb.recordset");
sqld="select sum(count) as dd from [count] where day(dae) = '"+((new Date).getDate())+"' and Month(dae) = '"+((new Date).getMonth()+1)+"' and Year(dae) = '"+((new Date).getYear())+"'";
rsd.open(sqld,conn,1,1);
//Realize yesterday's visits
var rsz = Server.CreateObject("adodb.recordset");
sqlz="select sum(count) as zd from [count] where day(dae) = '"+((new Date).getDate()-1)+"' and Month(dae) = '"+((new Date).getMonth()+1)+"' and Year(dae) = '"+((new Date).getYear())+"'";
rsz.open(sqlz,conn,1,1);
//Achieving monthly visits
var rsm = Server.CreateObject("adodb.recordset");
sqlm="select sum(count) as dm from [count] where Month(dae) = '"+((new Date).getMonth()+1)+"'";
%>
This article is a summary of the grammar of js+asp compiled by the editor of the False New Technology Channel. There are incorrect aspects of the above introduction. I hope you can put it forward, everyone can make progress and learn together.