Some of the areas that JavaScript needs to be aware of when writing ASP

Source: Internet
Author: User

Some of the areas that JavaScript needs to be aware of when writing ASP

Forum There are many people in the use of JavaScript to write ASP, often someone in the forum to ask, why the ASP object in contrast to the specified value returned the result is not correct? Here are some things to note about using JavaScript to write ASP.
The most common problem:

Code:

Response.Write(Request.Form("Key") == "") 


The result returned is "False". Here, we use typeof to discover that Request.Form ("Key") is actually returning an object, not a final value. So, we need to take out the final value to make the right judgments. You can use the following workaround:

Code:

var Nothing; //compatible with old versions of undefined without JScript
Response. Write (Request. Form ("Key"). Item ==  Nothing);
Response. Write (Request. Form ("Key"). Item ===  Nothing);
After IE 5.5 undefined is already a constant and can be accessed directly (the JScript version follows IE upgrades)
Response. Write (Request. Form ("Key"). Item ==  undefined );
Response. Write (Request. Form ("Key"). Item ===  undefined );
Response. Write (Request. Form ("Key"). Item ==  NULL );


Therefore, if we use the full value method when we take the value, we will not appear the strange phenomenon.

Here are some examples of how to take a value in asp:

QUOTE:
Example: Request.Form ("Key")
Value: Request.Form.Item ("Key"). Item
Or: Request.Form ("Key"). Item

Note the Request.Form.Item here, which returns a String object (value type) directly when the property is accessed, and returns an object when used as a JS "function".
Request.Cookies, Request.QueryString, request.servervariables the value of the same.
The shorthand request ("key") in the VBS corresponds to Request.item ("key") in JavaScript.

QUOTE:
Example: RS ("Filedname")
Take value: Rs. Fields.item ("Filedname"). Value
Or: Rs. Fields ("Filedname"). Value
Or: Rs ("Filedname"). Value

Here is a session and application.
We often use the session ("Key"), the return is already the final value, so this method can be used with ease. Incidentally, the full wording of the session should be:
Session.Contents.Item ("Key")
can also be written
Session.Contents ("Key")
Contents object seems a bit superfluous, in fact, it is not so, some times we still need to use it, mainly for the session of the enumeration and session of the remove operation. Such as:

Code:

Session.Contents.Remove("Key");
Session.Contents.RemoveAll() 


The Abandon method does not belong to the contents, it is a method that belongs to the session directly, need to pay attention to this when using.
Application also has contents objects, using the same usage as session.

Next, JS enumerates ASP objects.
Sometimes we might want to know what data the client is submitting. What data exist in the application or session?
In JS, we usually use the For...in method to get all the attributes of an object, but in ASP, this method is not available for ASP objects. What do we do? At this point, we can use enumerations (enumerator) and VBArray to get:

Code:

var app = new enumerator(application). Contents );
var arr = new Array;
while (! app . atEnd ())
{
var value = application. Contents . Item (app. Item ());
if (typeof value = = "Unknown") value = (New VBArray (value)). ToArray () +  "(vbarray)" ;
else value + = "(" + typeof value + ")" ;
arr. Push (app. Item () +  " : "  +  value );
app. MoveNext ();
}
Response. Write (arr. Join ("<br>"));


Write this, I hope to just start learning to use JS to write an ASP's friends some help.
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.