我正在编辑其他人的代码,用 ASP 的服务器端 JS 编写,遇到了一个问题,可能有一个非常简单的解决方案.
I am editing other people's code, written in server-side JS for ASP, and have run into a problem that probably has a very simple solution.
我正在从这样的 URL 参数中输出一些代码:
I'm outputting some code from a URL param like this:
<%=Request.QueryString("param")%>
问题是如果参数不存在,我需要做其他事情.所以我尝试了:
The problem is that if the param doesn't exist, I need to do something else. So I tried:
<%
var param = Request.QueryString("param");
if (!param) { param = "Some Default Value"; }
%>
<%=param%>
问题是 if 似乎永远不会评估为 true,即使 URL 参数丢失也是如此.我猜 !image 条件在这里不起作用.我的测试条件应该是什么?
The problem is that the if never seems to evaluate to true, even when the URL param is missing. I'm guessing that the !image condition doesn't work here. What should my test condition be?
(请放弃关于转义 URL 参数以防止 XSS 的严厉警告.)
(Please forgo stern warnings about doing escaping of URL params to prevent XSS.)
检查查询字符串参数是否存在的正确方法是使用 Count 属性:
The correct way to check whether a query string parameter exists is with the Count property:
<%
var param = Request.QueryString("param");
if (param.Count === 0) { param = "Some Default Value"; }
%>
<%=param%>
根据 的文档Request.QueryString,
Request.QueryString(parameter) 的值是一个包含所有QUERY_STRING 中出现的参数值.
The value of Request.QueryString(parameter) is an array of all of the values of parameter that occur in QUERY_STRING.
这可能是简单的 if (!param) 检查不起作用的原因.
That's probably why the simple if (!param) check doesn't work.
这篇关于查明 JS-ASP 中是否存在 URL 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
即使在调用 abort (jQuery) 之后,浏览器也会等待Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在调用 abort (jQuery) 之后,浏览器也会等待 ajax 调用
JavaScript innerHTML 不适用于 IE?JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不适用于 IE?)
XMLHttpRequest 无法加载,请求的资源上不存在“AXMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 无法加载,请求的资
XHR HEAD 请求是否有可能不遵循重定向 (301 302)Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 请求是否有可能不遵循重定向 (301 302))
XMLHttpRequest 206 部分内容XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分内容)
XMLHttpRequest 的 getResponseHeader() 的限制?Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)