I have been writing ASP in JS, which is not a special reason. I just learned JS at the beginning. Later, when I learned ASP, I knew that ASP could also be written in JS, so I didn’t learn VBS. When I first learned ASP a few months ago, I searched all book on bookstores in Shenzhen and didn’t find an ASP book using JS as a scripting language. I had no choice but to slowly explore and move forward. When I encountered something I didn’t understand, I searched online. Here, I post some differences between writing ASP and writing ASP in JS. I hope it will be helpful to friends who have just learned JS+ASP.
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:
<%
dimconn
dimdbpath
dimconnstr
Setconn=Server.CreateObject("adodb.connection")
dbpath=Server.MapPath("data.mdb")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="&dbpath
conn.openconnstr
%>
JS:
<%
varconn;
vardbpath;
varconnstr;
conn=Server.CreateObject("adodb.connection");
dbpath=Server.MapPath("data.mdb");
connstr="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+dbpath;
conn.open(connstr);
%>
Close the connection
VBS:
<%'Close Release Record Set
rs.close
setrs=Nothing
conn.close
setconn=Nothing
%>
JS:
<%//Close Release Record Set
rs.close;
rs=null;
conn.close;
conn=null;
%>
Output
VBS:
Response.write"<scriptlanguage='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("<scriptlanguage='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:
dimid
id=Request.QueryString("id")
JS:
variable=Request.QueryString("id").item;//Important, Request.QueryString in js is an object, and it needs to be added with Item
SQL statement date query, this is too different from VBS. I was depressed for a long time and searched for it 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)
<%
varrs,sql;
rs=Server.CreateObject("adodb.recordset");
sql="select*from[count]orderbydaedesc"
rs.open(sql,conn,1,1)
//Total visits are realized
varrst=Server.CreateObject("adodb.recordset");