Several similar expressions of server VBScript and JScript _ Javascript tutorial

Source: Internet
Author: User
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;
}
%>
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.