JavaScript: the server VBScript and JScript are written in the same way. Javascript tutorial
Methods of writing VBScript and JScript on the server with the same features
Abstract: This article demonstrates several important applications of ASP server scripts.
1. Traverse collection/Object
1.1 VBScript traversal form set
Linenum
<% For each temp in request. Form Response. write temp & ":" & request. form (temp) Next %> |
1.2 JScript traversal form set
Linenum
<% For (var $ e = new Enumerator (Request. Form );! $ E. atEnd (); $ e. moveNext ()){ Response. Write ($ e. item () + ': '+ Request. Form ($ e. item ())); } %> |
2. Convert the value to a variable and assign a value to it.
2.1 VBScript convert a value to a variable and assign a value
Linenum
<% For each temp in request. Form Execute temp & "= request. form (temp )" Next %> |
2.2 JScript convert a value to a variable and assign a value
Linenum
<% Var $ xml = new ActiveXObject ("microsoft. xmldom "); $ Xml. load (Server. MapPath ('config. xml ')); Var using childnodesusing using xml.doc umentElement. selectSingleNode ('// siteconfig'). childNodes
For ($ e = new Enumerator ($ childNodes );! $ E. atEnd (); $ e. moveNext ()){ Eval ($ e. item (). nodeName + "= $ e. item (). text "); } $ Xml = null; Response. Write (sitekeywords ); %> |
3. dynamically include files
3.1 VBScript dynamic File Inclusion
Linenum
<% Function fInclude (filepath) 'Sample call''' // execute fInclude ("include/system/language/" & sitefglang & "/main. asp ")\\\''' Dim cnt Cnt = CreateObject ("scripting. fileSystemObject"). openTextFile (server. MapPath (filepath). readall Cnt = replace (cnt, "<" & chr (37 ),"") Cnt = replace (cnt, chr (37) & "> ","") FInclude = cnt End function 'awl. qiu Code' Execute fInclude ("include/system/language/" & sitefglang & "/main. asp ") %> |
3.2 JScript dynamic inclusion
Linenum
<% Eval ($ dynInc ('aj2. asp ')); Response. Write ($ test );
Function $ dynInc ($ fl ){ /*------------------------------------\ * The JScript on the server dynamically contains the file By shawl. qiu * Sample call: eval ($ dynInc ('aj2. asp ')); \*------------------------------------*/ Var $ fso = new ActiveXObject ("scripting. fileSystemObject "); $ Str = $ fso. OpenTextFile (Server. MapPath ($ fl). ReadAll (); $ Str = $ str. replace (/\<\%|\%\>/g ,''); $ Fso = null; Return $ str; } %> |