在 VBscript 中访问 GET 变量时遇到问题
我是 VBscript 新手,因此可能有一个非常简单的解决方案。
基本上,我的主页上有一些按钮,它们实际上只是充当其他页面的链接。在链接中我想传递信息,所以我使用标准 ?variable=value ,如下所示:
<input type="button" name="saveButton" value="Save Systems" onclick="location.href='save.html?step=1'" />
<input type="button" name="loadButton" value="Load Systems" onclick="location.href='load.html?step=1'" />
我查找了如何访问 vbscript 中的 GET 变量,并且我查看的每个地方都说使用 Request.QueryString("variableName")
所以在我的save.html 页面我试图首先打印步骤的值,只是为了确保在开始实际处理所有代码之前我得到了它。这就是我挂断的地方。
<script type="text/vbscript">
document.write("<p>in the script<br>")
document.write("stepVar = ")
stepVar = Request.QueryString("step")
document.write(stepVar)
document.write(stepVar & "</p>")
</script>
... (rest of the page)
(我尝试了 2 个不同的打印语句,以防万一我错误地连接,但都不起作用。)当我单击主页上的“保存”按钮时,引导我到 save.html?step=1,它会打印
in the script
stepVar =
(rest of the page)
所以我猜步骤即将到来返回空?这不起作用的原因是因为我没有通过表单提交变量吗?应该跟这个没什么关系吧……?为什么我没有获取我的变量/如何获取“step”的值,以便我可以根据变量的值采取不同的操作?
I'm new to VBscript so there is probably a very simple solution to this.
Basically, I have my main page with buttons that really just act as links to other pages. In the links I wanted to pass information, so I use the standard ?variable=value like so:
<input type="button" name="saveButton" value="Save Systems" onclick="location.href='save.html?step=1'" />
<input type="button" name="loadButton" value="Load Systems" onclick="location.href='load.html?step=1'" />
I looked up how to access GET variables in vbscript and every place I looked said to use Request.QueryString("variableName")
So in my save.html page I'm trying to first print the value of step, just to make sure I'm getting it, before I start actually handling all my code. This is where I'm hung up.
<script type="text/vbscript">
document.write("<p>in the script<br>")
document.write("stepVar = ")
stepVar = Request.QueryString("step")
document.write(stepVar)
document.write(stepVar & "</p>")
</script>
... (rest of the page)
(I tried 2 different print statements just in case I was concatenating incorrectly, but neither work.) When I click my save button on the main page, leading me to save.html?step=1, it prints
in the script
stepVar =
(rest of the page)
So I guess step is coming back null? Is the reason this isn't working because I didn't submit my variable through a form? That shouldn't have anything to do with it... right? Why am I not getting my variable / how can I get the value of "step" so that I can take different actions depending on the value of my variable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Request.QueryString
适用于 ASP 页面中的 VBScript(或 ASP.net 页面中的 VB.net),它在服务器上执行,而不是在客户端浏览器中执行。如果您有正确配置的 Web 服务器,则保存为 .asp 页面的以下内容将输出您所期望的内容(服务器正在执行
<% %>
块内的所有内容);(如果您想在客户端 Web 浏览器中执行此操作,您可以使用
location
对象,这里是一个js示例,与VBScript不同,它可以在任何浏览器中工作)Request.QueryString
is for VBScript in an ASP page (or VB.net in an ASP.net page) that gets executed on the server, not in the clients browser.If you have a correctly configured web server the following saved as a .asp page would output what you expect (the server is executing everything inside the
<% %>
block);(If you wanted to do this in the client web browser you could use
location
object, here is a js example, which unlike VBScript will work in any browser)您可以使用客户端脚本来访问该值。此问题解决了类似的主题:
如何在 JavaScript 中获取查询字符串值?
You can use client script to access this value. This question addresses a similar topic:
How can I get query string values in JavaScript?
必须编写一个函数来解析 URL。在 javascript 中见过其中的几个,但我发现唯一一个用 VBScript 编写的没有使用正则表达式并且不起作用。在厌倦了尝试编译函数,然后吐出答案后,我决定使用正则表达式编写自己的函数,就像我见过的 JavaScript 函数(包括其他响应中链接的函数)对于这个问题)。
这样就再也没有人需要这样做了:
如果您使用 Option Explicit,则必须确保所有内容都已变暗,然后才能正常工作。我没有打扰。
如果其他人需要此功能,我鼓励重新发布此代码;我很沮丧,如此简单的事情给我带来了如此多的悲伤,并且不希望它发生在其他人身上!
Had to write a function to parse the URL. Seen several of these in javascript, but the only one I found written in VBScript didn't use regular expressions and DIDN'T WORK. After getting sick of trying to get the function to compile, and then to spit out an answer, I decided to write my own function using regular expressions, much like the javascript functions I'd seen (including the ones linked to in the other responses to this question).
So that no one ever has to do this again:
If you use Option Explicit you will have to make sure everything is Dim'd before this will work. I didn't bother.
I encourage reposting of this code if anyone else is in need of this functionality; I'm frustrated that something so simple caused me so much grief and wouldn't wish it on anyone else!