JavaScript类型检查Request值 [英] JavaScript typeof checking a Request value

查看:60
本文介绍了JavaScript类型检查Request值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


我在asp页面中有以下代码,其语言标记为:

<%@ LANGUAGE =" JAVASCRIPT" CODEPAGE =" 65001"%>


//查找请求变量。

var edition = Request.Form(" edition");

var language = Request.Form(" language");

Response.Write(" Edition is type& quot;" +(typeof edition)+" & quot;和

value& quot;" + edition +"& quot;< br>");

Response.Write(" ;语言类型& quot;" +(typeof language)+"& quot;

和value& quot;" + language +"& quot;< br> ;");


if(edition ==" undefined" ||

(typeof edition)==" undefined")

{

Response.Write(" Choose Page< br>");

Server.Execute(" choosePage.asp");

} //结束如果

其他

{

Response.Write(" View Page< br>" ;);

Server.Execute(" viewPage.asp");

} //结束其他


问题在于我所看到的:


版本是类型对象和值undefined

语言是类型对象和价值undefined

查看页面

choosePage.asp或viewPage.asp中没有任何内容,但我无法支付
找出为什么其他是触发而不是if - 我打印出的

版本var显示它的值为undefined......


任何帮助都将非常感激!


Rob

:)

Hi All!

I have the following code in an asp page whose language tag is:
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>

// Find request variables.
var edition = Request.Form ("edition");
var language = Request.Form ("language");
Response.Write("Edition is type &quot;" + (typeof edition) + "&quot; and
value &quot;" + edition + "&quot;<br>");
Response.Write("Language is type &quot;" + (typeof language) + "&quot;
and value &quot;" + language + "&quot;<br>");

if (edition == "undefined" ||
(typeof edition) == "undefined")
{
Response.Write("Choose Page<br>");
Server.Execute ("choosePage.asp");
} // end if
else
{
Response.Write("View Page<br>");
Server.Execute ("viewPage.asp");
} // end else

The problem is this is what I see:

Edition is type "object" and value "undefined"
Language is type "object" and value "undefined"
View Page
There is nothing in choosePage.asp or viewPage.asp yet, but I am unable to
figure out why the else is triggering and not the if - my print out of the
edition var shows it has a value of "undefined"...

Any help would be most appreciated!

Rob
:)

推荐答案

" Robert Mark Bram" <再******** @ removethis.optushome.com.au>写道:
"Robert Mark Bram" <re********@removethis.optushome.com.au> writes:
Response.Write(" Edition is type& quot;" +(typeof edition)+"& quot; and
value& quot ;" + edition +"& quot;< br>");
.... if(edition ==" undefined" ||
(typeof edition)==" undefined")
.... Edition是type" object"和值未定义


因此,版本是*对象*,当它转换为字符串时,它将成为字符串未定义。即,edition.toString()==" undefined"。


然后测试是否版本==未定义。 。它不是,因为它是一个

对象,而不是字符串,对象只等于它们。


同样,(typeof edition) =="未定义"因为(typeof

edition)==" object"。

但是我无法弄清楚为什么其他是触发而不是
如果 - 我打印出的版本var显示它的值为
undefined...
Response.Write("Edition is type &quot;" + (typeof edition) + "&quot; and
value &quot;" + edition + "&quot;<br>"); .... if (edition == "undefined" ||
(typeof edition) == "undefined") .... Edition is type "object" and value "undefined"
So, edition is an *object*, and when it is converted to a string, it
becomes the string "undefined". I.e., edition.toString() == "undefined".

You then test whether edition=="undefined" . It isn''t, since it is an
object, not a string, and objects are only equal to themselves.

Likewise, (typeof edition)=="undefined" fails since (typeof
edition)=="object".
but I am unable to figure out why the else is triggering and not the
if - my print out of the edition var shows it has a value of
"undefined"...




不,它的值是一个对象,这是值未定义都不是或者

字符串undefined。该对象有一个名为toString的方法,

返回字符串undefined。


/ L

-

Lasse Reichstein Nielsen - lr*@hotpop.com

Art D''HTML:< ; URL:http://www.infimum.dk/HTML/randomArtSplit.html>

''没有判断的信仰只会降低精神神圣。''



No, its value is an object, which is neither the value "undefined" or
the string "undefined". That object has a method called toString that
returns the string "undefined".

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D''HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
''Faith without judgement merely degrades the spirit divine.''


Hi Lasse - 感谢您的回复!

Hi Lasse - thank you for your response!

Response.Write(" Edition is type& quot ;" +(typeof edition)+"& quot;
和value& quot;" + edition +"& quot;< br>");
Response.Write("Edition is type &quot;" + (typeof edition) + "&quot; and value &quot;" + edition + "&quot;<br>");


...


...

if(edition ==" undefined" ||
(typeof edition)==" undefined")
if (edition == "undefined" ||
(typeof edition) == "undefined")


...


...

Edition是type" object"和值undefined
Edition is type "object" and value "undefined"



因此,edition是一个* object *,当它转换为字符串时,它将成为字符串undefined。即,edition.toString()==" undefined"。



So, edition is an *object*, and when it is converted to a string, it
becomes the string "undefined". I.e., edition.toString() == "undefined".




我刚试过这个并且让事情变得更加混乱:


if(edition.toString()==" undefined")

{

Response.Write(" Choose Page< br>");

Server.Execute(" choosePage.asp");

} //结束如果

else

{

Response.Write(" View Page< br>");

Server.Execute(" viewPage.asp");

} //结束其他


结果错误:

错误类型:

Microsoft JScript运行时(0x800A01B6)

对象不支持此属性或方法

/polyprint/newsletter.asp,第16行

第16行是行:

if(edition.toString()==" undefined")


它怎么可能是一个对象而没有toString?


Rob

:)



I just tried this and got something even more confusing:

if (edition.toString() == "undefined")
{
Response.Write("Choose Page<br>");
Server.Execute ("choosePage.asp");
} // end if
else
{
Response.Write("View Page<br>");
Server.Execute ("viewPage.asp");
} // end else

The resulting error:
Error Type:
Microsoft JScript runtime (0x800A01B6)
Object doesn''t support this property or method
/polyprint/newsletter.asp, line 16

Line 16 is the line:
if (edition.toString() == "undefined")

How can it be an Object and not have toString?

Rob
:)


" Robert M ark Bram <再******** @ removethis.optushome.com.au>写道:
"Robert Mark Bram" <re********@removethis.optushome.com.au> writes:
我只是尝试了这个并且让事情变得更加混乱:


确实!

if(edition .toString()==" undefined")
....结果错误:
错误类型:
Microsoft JScript运行时(0x800A01B6)
对象不支持这个属性或方法
/polyprint/newsletter.asp,第16行
第16行是行:
if(edition.toString()==" undefined")

如何成为一个Object而不是toString?
I just tried this and got something even more confusing:
Indeed!
if (edition.toString() == "undefined") .... The resulting error:
Error Type:
Microsoft JScript runtime (0x800A01B6)
Object doesn''t support this property or method
/polyprint/newsletter.asp, line 16

Line 16 is the line:
if (edition.toString() == "undefined")

How can it be an Object and not have toString?




有一个值为object的类型的值这不是一个对象:

null值。但是,将其转换为字符串会给出null,而不是

" undefined" (至少它应该符合ECMAScript标准)。


所有Javascript对象都有一个原型链,结尾于

Object.prototype,它有一个toString方法。但是,本机

对象几乎可以任意奇怪。


试试这个:


if(edition == = undefined){

Response.Write(" undefined< br>");

}

if(edition === null ){

Response.Write(" null< br>");

}

if("" + edition = =" undefined"){

Repsonse.Write(" string:undefined< br>");

}

if( edition!== undefined&& edition!== null){

for(var i in edition){

Response.Write(i +" =" ; +版[i] +"< br>);

}

}


如果是对象无论如何,这可能会说明它是什么物品。


/ L

-

Lasse Reichstein Nielsen - lr*@hotpop.com

Art D''HTML: <的URL:http://www.infimum.dk/HTML/randomArtSplit.html>
''没有判断的信仰只会降低精神神圣。''



There is one value with a typeof of "object" that isn''t an object: the
null value. However, converting that to a string gives "null", not
"undefined" (at least it should according to the ECMAScript standard).

All Javascript objects have a prototype chain that ends at
Object.prototype, which has a toString method. However, native
objects can act almost arbitrarily strange.

Try this:

if (edition === undefined) {
Response.Write("undefined<br>");
}
if (edition === null) {
Response.Write("null<br>");
}
if (""+edition == "undefined") {
Repsonse.Write("string:undefined<br>");
}
if (edition !== undefined && edition !== null) {
for(var i in edition) {
Response.Write(i+"="+edition[i]+"<br>);
}
}

If it is an object of any kind, this might shed some light on which
kind of object it is.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D''HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
''Faith without judgement merely degrades the spirit divine.''


这篇关于JavaScript类型检查Request值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆