Vbscript 如何使用新的查询字符串重新加载ASP页面?

Vbscript 如何使用新的查询字符串重新加载ASP页面?,vbscript,asp-classic,query-string,Vbscript,Asp Classic,Query String,在VBScript中,每次运行此代码时都会出现错误。如果在querystring中找不到“p”变量,我只想重新加载页面 我到底做错了什么 Dim sURL 'URL of the document sURL = document.URL 'Set page number equal to 1 If( InStr( sUrl, "?" ) = 0 ) Then sURL = sURL & "?p=1" window.location = sURL

在VBScript中,每次运行此代码时都会出现错误。如果在
querystring
中找不到“p”变量,我只想重新加载页面

我到底做错了什么

Dim sURL            'URL of the document
sURL = document.URL

'Set page number equal to 1
If( InStr( sUrl, "?" ) = 0 ) Then
    sURL = sURL & "?p=1"
    window.location = sURL
    window.location.reload()
End If

你做错了什么?看起来几乎什么都有。您的代码看起来像是一堆VBS和JavaScript

你需要的是

<%@LANGUAGE=VBSCRIPT%>
<%
    If Request.QueryString("p") = "" Then
        Response.Redirect Request.ServerVariables("URL") & "?p=1"
    Else
        Response.Write "YES! WE HAVE IT!"
    End If
%>

你做错了什么?看起来几乎什么都有。您的代码看起来像是一堆VBS和JavaScript

你需要的是

<%@LANGUAGE=VBSCRIPT%>
<%
    If Request.QueryString("p") = "" Then
        Response.Redirect Request.ServerVariables("URL") & "?p=1"
    Else
        Response.Write "YES! WE HAVE IT!"
    End If
%>

你做错了什么?看起来几乎什么都有。您的代码看起来像是一堆VBS和JavaScript

你需要的是

<%@LANGUAGE=VBSCRIPT%>
<%
    If Request.QueryString("p") = "" Then
        Response.Redirect Request.ServerVariables("URL") & "?p=1"
    Else
        Response.Write "YES! WE HAVE IT!"
    End If
%>

你做错了什么?看起来几乎什么都有。您的代码看起来像是一堆VBS和JavaScript

你需要的是

<%@LANGUAGE=VBSCRIPT%>
<%
    If Request.QueryString("p") = "" Then
        Response.Redirect Request.ServerVariables("URL") & "?p=1"
    Else
        Response.Write "YES! WE HAVE IT!"
    End If
%>

您可以使用

 If( InStr( sUrl, "?" ) = 0 ) Then
    sURL = sURL & "?p=1"
   window.location.href =  sURL & "?p=1"
 End If
你可以用

 If( InStr( sUrl, "?" ) = 0 ) Then
    sURL = sURL & "?p=1"
   window.location.href =  sURL & "?p=1"
 End If
你可以用

 If( InStr( sUrl, "?" ) = 0 ) Then
    sURL = sURL & "?p=1"
   window.location.href =  sURL & "?p=1"
 End If
你可以用

 If( InStr( sUrl, "?" ) = 0 ) Then
    sURL = sURL & "?p=1"
   window.location.href =  sURL & "?p=1"
 End If

为什么要麻烦?您只是假设一个默认值,因此当您处理页面并查找
p
QueryString值时,如果没有匹配的值,只需将其设置为默认值

Dim p
p = Request.QueryString("p")
If "" & p = "" Then p = 1
无需重新加载任何页面

为了更进一步,我倾向于使用这样的函数

'GetPostData
'   Obtains the specified data item from the previous form get or post.
'Usage:
'   thisData = GetPostData("itemName", "Alternaitve Value")
'Parameters:
'   dataItem (string) - The data item name that is required.
'   nullVal (variant) - The alternative value if the field is empty.
'Description:
'   This function will obtain the form data irrespective of type (i.e. whether it's a post or a get).
'Revision info:
'   v0.2 -      Function has been renamed to avoid confusion.
'   v0.1.2 -    Inherent bug caused empty values not to be recognised.
'   v0.1.1 -    Converted the dataItem to a string just in case.
function GetPostData(ByVal dataItem, ByVal nullVal)
    dim rV
    'Check the form object to see if it contains any data...
    if request.Form("" & dataItem) = "" then
        if request.QueryString("" & dataItem)="" then 
            rV = CStr(nullVal)
        else
            rV = request.QueryString("" & dataItem)
        end if
    else
        rV = request.Form("" & dataItem)
    end if
    'Return the value...
    GetPostData = rV
end function

…保持我的代码整洁。如果所发布的数据丢失,该函数只返回一个默认值。请注意,此函数实际上会在返回默认值之前检查QueryString和表单数据。

何必麻烦呢?您只是假设一个默认值,因此当您处理页面并查找
p
QueryString值时,如果没有匹配的值,只需将其设置为默认值

Dim p
p = Request.QueryString("p")
If "" & p = "" Then p = 1
无需重新加载任何页面

为了更进一步,我倾向于使用这样的函数

'GetPostData
'   Obtains the specified data item from the previous form get or post.
'Usage:
'   thisData = GetPostData("itemName", "Alternaitve Value")
'Parameters:
'   dataItem (string) - The data item name that is required.
'   nullVal (variant) - The alternative value if the field is empty.
'Description:
'   This function will obtain the form data irrespective of type (i.e. whether it's a post or a get).
'Revision info:
'   v0.2 -      Function has been renamed to avoid confusion.
'   v0.1.2 -    Inherent bug caused empty values not to be recognised.
'   v0.1.1 -    Converted the dataItem to a string just in case.
function GetPostData(ByVal dataItem, ByVal nullVal)
    dim rV
    'Check the form object to see if it contains any data...
    if request.Form("" & dataItem) = "" then
        if request.QueryString("" & dataItem)="" then 
            rV = CStr(nullVal)
        else
            rV = request.QueryString("" & dataItem)
        end if
    else
        rV = request.Form("" & dataItem)
    end if
    'Return the value...
    GetPostData = rV
end function

…保持我的代码整洁。如果所发布的数据丢失,该函数只返回一个默认值。请注意,此函数实际上会在返回默认值之前检查QueryString和表单数据。

何必麻烦呢?您只是假设一个默认值,因此当您处理页面并查找
p
QueryString值时,如果没有匹配的值,只需将其设置为默认值

Dim p
p = Request.QueryString("p")
If "" & p = "" Then p = 1
无需重新加载任何页面

为了更进一步,我倾向于使用这样的函数

'GetPostData
'   Obtains the specified data item from the previous form get or post.
'Usage:
'   thisData = GetPostData("itemName", "Alternaitve Value")
'Parameters:
'   dataItem (string) - The data item name that is required.
'   nullVal (variant) - The alternative value if the field is empty.
'Description:
'   This function will obtain the form data irrespective of type (i.e. whether it's a post or a get).
'Revision info:
'   v0.2 -      Function has been renamed to avoid confusion.
'   v0.1.2 -    Inherent bug caused empty values not to be recognised.
'   v0.1.1 -    Converted the dataItem to a string just in case.
function GetPostData(ByVal dataItem, ByVal nullVal)
    dim rV
    'Check the form object to see if it contains any data...
    if request.Form("" & dataItem) = "" then
        if request.QueryString("" & dataItem)="" then 
            rV = CStr(nullVal)
        else
            rV = request.QueryString("" & dataItem)
        end if
    else
        rV = request.Form("" & dataItem)
    end if
    'Return the value...
    GetPostData = rV
end function

…保持我的代码整洁。如果所发布的数据丢失,该函数只返回一个默认值。请注意,此函数实际上会在返回默认值之前检查QueryString和表单数据。

何必麻烦呢?您只是假设一个默认值,因此当您处理页面并查找
p
QueryString值时,如果没有匹配的值,只需将其设置为默认值

Dim p
p = Request.QueryString("p")
If "" & p = "" Then p = 1
无需重新加载任何页面

为了更进一步,我倾向于使用这样的函数

'GetPostData
'   Obtains the specified data item from the previous form get or post.
'Usage:
'   thisData = GetPostData("itemName", "Alternaitve Value")
'Parameters:
'   dataItem (string) - The data item name that is required.
'   nullVal (variant) - The alternative value if the field is empty.
'Description:
'   This function will obtain the form data irrespective of type (i.e. whether it's a post or a get).
'Revision info:
'   v0.2 -      Function has been renamed to avoid confusion.
'   v0.1.2 -    Inherent bug caused empty values not to be recognised.
'   v0.1.1 -    Converted the dataItem to a string just in case.
function GetPostData(ByVal dataItem, ByVal nullVal)
    dim rV
    'Check the form object to see if it contains any data...
    if request.Form("" & dataItem) = "" then
        if request.QueryString("" & dataItem)="" then 
            rV = CStr(nullVal)
        else
            rV = request.QueryString("" & dataItem)
        end if
    else
        rV = request.Form("" & dataItem)
    end if
    'Return the value...
    GetPostData = rV
end function

…保持我的代码整洁。如果所发布的数据丢失,该函数只返回一个默认值。请注意,此函数实际上会在返回默认值之前检查QueryString和表单数据。

问题被标记为vbscript,但您已经给出了JavaScript答案。正如在另一个解决方案中指出的,最初的问题最大限度地混合了两者。这显然不是JavaScript的答案(
End If
是VB,而不是JS)。虽然这个答案可能是正确和有用的,但如果您在答案中包含一些解释,以解释它如何帮助解决问题,则更可取。如果有一个变化(可能无关)导致它停止工作,并且用户需要了解它曾经是如何工作的,那么这在将来变得特别有用。它当然看起来像VBS,但
window。location
表明它是客户端代码。客户端VBS是与ASP不同的东西(它仅由Internet Explorer支持)@John是100%正确的这是客户端VBScript,它仅由IE支持,但很少有公司仍在企业内部网(受控环境)中使用它。问题被标记为VBScript,但您给出了JavaScript答案。正如在另一个解决方案中指出的,最初的问题最大限度地混合了两者。这显然不是JavaScript的答案(
End If
是VB,而不是JS)。虽然这个答案可能是正确和有用的,但如果您在答案中包含一些解释,以解释它如何帮助解决问题,则更可取。如果有一个变化(可能无关)导致它停止工作,并且用户需要了解它曾经是如何工作的,那么这在将来变得特别有用。它当然看起来像VBS,但
window。location
表明它是客户端代码。客户端VBS是与ASP不同的东西(它仅由Internet Explorer支持)@John是100%正确的这是客户端VBScript,它仅由IE支持,但很少有公司仍在企业内部网(受控环境)中使用它。问题被标记为VBScript,但您给出了JavaScript答案。正如在另一个解决方案中指出的,最初的问题最大限度地混合了两者。这显然不是JavaScript的答案(
End If
是VB,而不是JS)。虽然这个答案可能是正确和有用的,但如果您在答案中包含一些解释,以解释它如何帮助解决问题,则更可取。如果有一个变化(可能无关)导致它停止工作,并且用户需要了解它曾经是如何工作的,那么这在将来变得特别有用。它当然看起来像VBS,但
window。location
表明它是客户端代码。客户端VBS是与ASP不同的东西(它仅由Internet Explorer支持)@John是100%正确的这是客户端VBScript,它仅由IE支持,但很少有公司仍在企业内部网(受控环境)中使用它。问题被标记为VBScript,但您给出了JavaScript答案。正如在另一个解决方案中所指出的,最初的问题是max将两者混合在一起。这显然不是一个JavaScript