gpt4 book ai didi

javascript - 指定单击链接时要加载的 xml 文件

转载 作者:行者123 更新时间:2023-12-02 19:24:29 25 4
gpt4 key购买 nike

我希望这样当点击主页上的链接时,它会将特定的 xml 文件加载到下一页(该页面称为category-list.apsx)。

该类别列表页面使用Repeater Control方法在页面上显示xml详细信息。我使用了此处显示的示例:

http://www.w3schools.com/aspnet/aspnet_repeater.asp

所以目前中继器脚本如下所示:

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycategories=New DataSet
mycategories.ReadXml(MapPath("categories.xml"))
categories.DataSource=mycategories
categories.DataBind()
end if
end sub
</script>

经过一些研究,我确实发现有人遇到同样的问题,解决方案是插入#tags作为主页上链接的一部分(即category-list.apsx#company1results),然后在列表页面上插入一些脚本选择正确的 xml 文件:

<script type="text/javascript">
var old_onload = window.onload; // Play it safe by respecting onload handlers set by other scripts.
window.onload=function()
{
var categories = document.location.href.substring(document.location.href.indexOf("#")+1);
loadXMLDoc('XML/'+categories+'.xml');
old_onload();
}
</script>

这来自以下链接:

http://www.hotscripts.com/forums/javascript/45641-solved-specify-xml-file-load-when-click-link.html

如何让这两个脚本相互连接?

最佳答案

使用查询字符串代替哈希“#”更容易,因为查询字符串将发送到服务器端,因此不需要客户端 JavaScript。

因此,当您调用category-list.apsx?cat=company1results时,可以使用以下代码在xml文件之间进行切换:

Public Sub Page_Load()
If Not Page.IsPostBack Then
Dim cat As String = Request.QueryString("cat")

Dim mycategories As DataSet = New DataSet()
mycategories.ReadXml(MapPath(cat + ".xml"))
categories.DataSource = mycategories
categories.DataBind()
End If
End Sub

关于javascript - 指定单击链接时要加载的 xml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12193940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com