一、IIS 服务器配置
启用目录浏览
打开 IIS 管理器 → 选择目标网站或虚拟目录 → 双击 "目录浏览" → 右侧点击 "启用"。
确保勾选 "时间"、"大小"、"扩展名" 等显示选项(可选)。
配置 MIME 类型(可选)
若需直接返回文件列表的 JSON 数据(而非 HTML),需添加 MIME 类型:
右键网站 → "MIME 类型" → 添加:
扩展名:.json
MIME 类型:application/json
跨域访问配置(CORS)
若请求跨域,需在 IIS 中添加响应头:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET" />
</customHeaders>
</httpProtocol>
</system.webServer>
二、JS访问代码
esriRequest(attachbaseUrl + results.features[0].attributes.xh, {
responseType: "text" // 接收原始 HTML 内容
}).then(function (response) {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(response.data, "text/html");
const links = htmlDoc.querySelectorAll("a"); // 提取所有链接
const fileList = Array.from(links)
.map(link => link.getAttribute("href"))
.filter(name => !name.endsWith("/")); // 过滤子目录
fileList.forEach(function (attachment) {
if (attachment.split(".")[1] === "jpg") {
const image = document.createElement("img");
image.src = attachment;
image.className = "queryImg";
document.getElementById("queryResults").appendChild(image);
} else if (attachment.split(".")[1] === "mp4") {
const videodiv = document.createElement("video");
videodiv.src = attachment;
videodiv.autoplay = true;
videodiv.muted = true; // 关键:绕过浏览器自动播放限制[1,3](@ref)
videodiv.loop = true;
videodiv.className = "queryImg";
document.getElementById("queryResults").appendChild(videodiv);
}
else{
}
});
三、效果
image.png