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:
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:
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:
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:
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.