经典 ASP:查询字符串处理程序

发布于 2024-09-13 18:29:51 字数 845 浏览 1 评论 0原文

我很久以前就做过了,现在找不到这个功能了。它不应该太复杂,但我想知道在我再次执行此操作之前是否有任何新闻...

采取这个:

www.example.com?query=whatever&page=1

现在想象我按按钮到第 2 页,它将变成:

www.example.com?query=whatever&page=2

始终保留查询字符串的其余部分完好无损的。现在第 2 页上的图片 我按下按钮按日期排序,它应该变成:

www.example.com?query=whatever&page=1&order=date

问题是,在用于排序的 ASP 代码上,我不想处理所有其他查询字符串。因此,我需要一个函数来为我处理它,并且能够执行类似以下示例的操作:

<a href="?<%= add_querystring(qs, "order", "date") %>">date</a>
<a href="?<%= set_querystring(qs, "page", page + 1) %>">next page</a>
<a href="?<%= add_querystring(del_querystring(qs, "page"), "allpages") %>">all pages</a>

这只是如果我仍然找不到现成的解决方案,我将要做什么的初步想法......再说一次,只是想知道是否有任何新的东西可以以我还没有想象到的方式来处理这一切。

I've done this a long time ago, now I can't find the function. It shouldn't be too complicated, but I wonder if there's any news on this before I go and do it again...

Take this:

www.example.com?query=whatever&page=1

Now imagine I press button to page 2, it will become:

www.example.com?query=whatever&page=2

Always keeping the rest of the querystring intact. Now picture on page 2 I press the button to order by date, it should turn into:

www.example.com?query=whatever&page=1&order=date

Problem is, on the ASP code for ordering, I don't want to handle every other querystring. So I need a function to handle it for me and be able to do something like the following examples:

<a href="?<%= add_querystring(qs, "order", "date") %>">date</a>
<a href="?<%= set_querystring(qs, "page", page + 1) %>">next page</a>
<a href="?<%= add_querystring(del_querystring(qs, "page"), "allpages") %>">all pages</a>

This is just an initial idea of what I am going to do if I still can't find a ready solution... Again, just wondering if there's anything new out there to handle all this in ways I haven't even imagined yet.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回首观望 2024-09-20 18:29:51

如果有人感兴趣,这是我昨天滚动的相当混乱的代码:

'Build a string QueryString from the array Request
function bdl_qs (req_qs)
    dim result, qa, item
    result = empty
    qa = "?"
    if isnull(req_qs) or isempty(req_qs) then req_qs = Request.QueryString
    for each item in req_qs
        result = result & qa & item
        result = result & "=" & req_qs(item)
        qa = "&"
    next
    bdl_qs = result
end function

'Build a string QueryString ontop of the supplied one, adding the query and / or value(s) to it
function add_qs (qs, q, s)
    dim result
    result = qs
    if left(result, 1) = "?" then
        result = result & "&" & q
    else
        result = "?" & q
    end if
    if not isnull(s) and not isempty(s) then 
        result = result & "=" & s
    end if  
    add_qs = result
end function

'Build a string QueryString ontop of the supplied one, removing the selected query and / or values
function del_qs (qs, q)
    dim result, item
    result = qs
    if left(qs, 1) = "?" then
        dim rqs, qa
        rqs = result
        result = "?"
        rqs = right(rqs, len(rqs)-1) 'remove the "?"
        rqs = Split(rqs, "&") 'separate the queries
        qa = ""
        for each item in rqs
            dim rq
            rq = Split(item, "=") 'separate the query to analyze the name only
            if rq(0) <> q then 'good for rebuilding
                result = result & qa & item
                qa = "&"
            end if
        next
    end if
    del_qs = result
end function

'Build a string QueryString ontop of the supplied one, setting the query to the value
function set_qs (qs, q, s)
    set_qs = add_qs(del_qs(qs, q), q, s)
end function

If it's of anyone's interest, here's the quite confusing code I rolled on yesterday:

'Build a string QueryString from the array Request
function bdl_qs (req_qs)
    dim result, qa, item
    result = empty
    qa = "?"
    if isnull(req_qs) or isempty(req_qs) then req_qs = Request.QueryString
    for each item in req_qs
        result = result & qa & item
        result = result & "=" & req_qs(item)
        qa = "&"
    next
    bdl_qs = result
end function

'Build a string QueryString ontop of the supplied one, adding the query and / or value(s) to it
function add_qs (qs, q, s)
    dim result
    result = qs
    if left(result, 1) = "?" then
        result = result & "&" & q
    else
        result = "?" & q
    end if
    if not isnull(s) and not isempty(s) then 
        result = result & "=" & s
    end if  
    add_qs = result
end function

'Build a string QueryString ontop of the supplied one, removing the selected query and / or values
function del_qs (qs, q)
    dim result, item
    result = qs
    if left(qs, 1) = "?" then
        dim rqs, qa
        rqs = result
        result = "?"
        rqs = right(rqs, len(rqs)-1) 'remove the "?"
        rqs = Split(rqs, "&") 'separate the queries
        qa = ""
        for each item in rqs
            dim rq
            rq = Split(item, "=") 'separate the query to analyze the name only
            if rq(0) <> q then 'good for rebuilding
                result = result & qa & item
                qa = "&"
            end if
        next
    end if
    del_qs = result
end function

'Build a string QueryString ontop of the supplied one, setting the query to the value
function set_qs (qs, q, s)
    set_qs = add_qs(del_qs(qs, q), q, s)
end function
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文