gpt4 book ai didi

javascript - 从文件夹加载图像时 Ajax 调用抛出 404

转载 作者:行者123 更新时间:2023-11-29 20:55:58 25 4
gpt4 key购买 nike

我正在尝试通过 jquery 和 ajax 从文件夹加载图像,我正在使用提供的解决方案 here .但是,这会引发 404 错误 - 即使该目录确实存在,而且我什至可以访问其中的文件。

这是 jquery 代码:

$(document).ready(function () {
var folder = "images/";

$.ajax({
url: folder,
success: function (data) {
$(data).find("a").attr("href", function (i, val) {
if (val.match(/\.(jpe?g|png|gif)$/)) {
$('#galerie').append('<a class="image_anchor" data-fancybox="gallery" href="resources/img/header_bg.jpg"><img src="' + folder + val + '" /></a>')
}
});
}
});
});

最佳答案

正如 question 中提到的那样你看着

//This will retrieve the contents of the folder if the folder is configured as 'browsable'

将 .htaccess 文件放在图像所在的目录中。 .htaccess 文件的内容应如下所示:

Options +Indexes

更多信息:https://support.tigertech.net/directory-index

请记住,您需要在网络服务器上运行该页面,因为您使用的是 .htaccess(不需要 PHP)

关于javascript - 从文件夹加载图像时 Ajax 调用抛出 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49347165/

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