【发布时间】:2018-12-04 20:51:06
【问题描述】:
我做了一个程序,用于在本地保存图像,并将该图像的 url 保存在数据库中。在使用 ajax 从数据库中检索数据时,它会给我 url,我将在这些 url 后面附加一个 div 类,下面给出了 ajax 的代码:-
$( document ).ready(function() {
$.ajax({
url: "/api/v1/get-all-upload-image?sortBy=date",
type: "GET",
success: function(response){
console.log(response);
for (i= 0; i < response.response.data.length; i++){
console.log(response.response.data[i])
$(".images").html('<img src='+response.response.data[i].image_url+' alt="Smiley face" height="42" width="42">')
}
}
});
});
图片网址是这样的
这不会显示任何内容,但当我删除 http://localhost:8080 时,它将显示图像。谁能告诉我为什么会这样?我将如何访问此图像?
【问题讨论】:
-
您应该尝试将图像放入您的项目(资产目录)中,您可以试试吗?
-
是的@DimitriusLachi 我试过了,但是当我删除
http://localhost:8080时它不起作用,它会显示我的图像 -
您的控制台显示错误?可能是图片路径不正确
-
@DimitriusLachi 看看控制台在说什么
GET http://localhost:8080/home/iron/go/uploads/xyz/themes/2018/12/4/1543926011rtx2qo8te1498751170626.jpg 404 (Not Found) -
图片不在你的项目目录中