javascript - ajax成功后点击事件的jQuery Fancybox显示没有图像
问题描述
在 ajax 请求的成功区域中,我通过 jQuery 添加了一个 onClick eventListener 来打开 fancybox。画廊的对象被接收并通过数据属性传递。
jQuery.ajax({
type: "post",
dataType: "json",
url: ajax_url,
data: data,
success: function( response ) {
poi_images = '';
if(poi_data['images'] !== undefined) {
poi_gallery_class = 'poi-gallery';
poi_images = JSON.stringify(poi_data['images']);
}
// [...]
$('.poi-gallery').on('click', function() {
gallery = $(this).attr('data-gallery');
gallery = JSON.parse(gallery);
console.log(gallery);
$.fancybox.open(
gallery, {
helpers : {
thumbs : {
width: 75,
height: 50
}
},
});
});
}
});
fancybox 画廊打开,在画廊中显示正确数量的图像,但没有显示任何图像。Container 还是空的,fancybox 镜像的 src 还是空的。
我做错了什么?
解决方案
发现图像 url 的键名必须命名为“src”而不是“href”。
推荐阅读
- django - 如何过滤哨兵上的错误以避免消耗我的配额?
- linux - 如何在linux中借助du获取目录中所有文件的组合磁盘空间
- pandas - Pandas:如何将日期时间转换为 %H:%H 并保持日期时间格式?
- python - 如果将“子”对象分配给 SQLAlchemy 中的“关系”,如何在“父”对象上设置属性?
- ios - 关于在 Swift 的静态 tableviewController 中放置固定按钮的问题
- mysql - 如何在 SQL 中查询字典类型的列值?
- kubernetes - 在部署文件上添加 --record=true - Kubernetes
- sql - 从另一个表 sql server 计算总时间和更新值
- sqlite - Flutter:将所有数据插入数据库后如何通知主小部件
- javascript - Chromium 中的 Java 和 JS 之间的通信