javascript - 如何在 javascript 中以 json 形式显示来自 laravel 控制器的图像
问题描述
我的代码中有数据中的图像
$(document).ready(function(){
$('.show-btn').click(function() {
var pid = $(this).data("id");
//alert(pid);
$.ajax({
type:'get',
url:'home/dataajex/'+pid,
dataType:"json",
success:function(data) {
data.forEach(function(element) {
var imgSource = document.getElementById('data').src ;
document.body.appendChild(load_data);
console.log(imgSource);
});
console.log(data);
}
});
});
});
我如何在其中显示图像我的 html div id 是 load_data
解决方案
尝试这个,
$.ajax({
type:'get',
url:'home/dataajex/'+pid,
dataType:"json",
success:function(data) {
$.each(data, function(index) {
$('#yourDivId').append("<img src='"+data[index]+"'>");
}
}
});
推荐阅读
- regex - 正则表达式排除非 ASCII 但保留北欧字符
- javascript - 在 JavaScript 中寻找 const 函数的解释
- sql-server - 如何从给定的代码集创建视图
- matlab - Matlab:如何读/写现有的(1 * 2)结构?
- bash - 我有一个 body.html 文件,我想将其作为电子邮件正文以及使用 sendmail 或 mail 的附件发送。如何做到这一点?
- php - 相同的数据节省了两次?
- matlab - Matlab中的mexw64类型文件
- java - 在android中使用新的SQLite数据库恢复和删除旧的SQLite数据库
- java - 通过“java -jar”运行应用程序的JVM设置最佳实践
- csv - go - 如何修复golang中CSV文件中缺少逗号的“错误数量的字段”?