Js+asp Summary _asp Foundation

Source: Internet
Author: User
Tags getdate
have been using JS to write ASP, is not a special reason, just learned is JS, and later learned that ASP can also use JS to write, did not go to learn VBS. A few months ago just learn ASP when the bookstore in Shenzhen did not find a copy of the script language with JS ASP books, no way, Can only slowly groping forward, encounter do not understand things on the internet search, here, send some JS write ASP and VBS write the difference between ASP, hope to just learn js+asp friend help.

Grammar Summary: JS statement at the end of the add;
Write the SQL statement to change the & number in the VBS to the + number,
JS in the simple note is//, the whole paragraph is * * Here is the code to annotate * * *,
Variable declaration is the var keyword, no need to write set, direct Var on line,
The first letter of the ASP object is capitalized, such as when the server's S is written to capitalize, or it will report an error.

The difference between some code

Connecting to a 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 connection
VBS:
<% ' off release recordset
Rs.close
Set rs = Nothing
Conn.close
Set conn = Nothing
%>

Js:
<%//off release recordsets
Rs.close;
rs = null;
Conn.close;
conn = null;
%>

Output
VBS:
Response.Write "<script language= ' JavaScript ' >alert (' the operation was successful, please wait for admin to confirm \ OK close window '); Self.opener.location.reload ( ); Window.close ();</script> "

Js:
Response.Write (' <script language= ' JavaScript ' >alert (' Operation succeeded, please wait for admin to confirm \ OK close window '); self.opener.location.reload (); Window.close ();</script> ");


Get Form objects
VBS:
Dim id
id = request.querystring ("id")

Js:
var id = request.querystring ("id"). item;//important, JS Request.QueryString is an object, to add the item



SQL Statement Date query, this is too different from the VBS, the beginning of my depressed for a long time, on the internet for a long time to come up with the following statement (this only wrote JS, the VBS will not write)
<%
var rs,sql;
rs = Server.CreateObject ("Adodb.recordset");
sql = "SELECT * from [Count] to Dae Desc"
Rs.Open (sql,conn,1,1)
Total number of visits achieved
var rst = Server.CreateObject ("Adodb.recordset");
sqlt= "Select SUM (count) as DT from [Count]";
Rst.open (sqlt,conn,1,1);
Achieve Day traffic
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). g Etmonth () +1) + "' and year (DAE) = '" + ((new Date). getyear ()) + "'";
Rsd.open (sqld,conn,1,1);
To achieve yesterday's visit volume
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);
To achieve the month's traffic
var rsm = Server.CreateObject ("Adodb.recordset");
sqlm= Select SUM (count) as DM from [Count] where Month (dae) = ' "+ (new Date). GetMonth () +1) +" ' ";
%>

Temporarily think so much, by the way, I am very vegetable, the above should have incorrect place also hope Gao pointed out.
I hope that the moderator will be affixed to the top, after the relevant JS write ASP questions can be presented here. Let some learn js write ASP's friends have a better communication space.
Related Article

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.