我在Visual Studio 2012是新的,我有一个项目,我需要一些图像加载到通过JavaScript一看,基本上我都充满了一些项目的描述和每个路径的数组图像,但是当页面加载页面不能因为它从来没有发现他们加载图像问题加载图像2012
我用来实现这一目标的JavaScript代码:
var item = {
name: "",
price: 0,
index: 0,
picURL: ""
};
function Item(name, price, index, picURL) {
this.name = name;
this.price = price;
this.index = index;
this.picURL = picURL;
}
function FillArray() {
var items = new Array();
items[0] = new Item("Gnome1", 32, 001, "Content/img/gnome7.PNG");
items[1] = new Item("Gnome2", 15, 002, "Content/img/gnome14.PNG");
items[2] = new Item("Gnome3", 26, 003, "Content/img/gnome10.PNG");
return items;
}
function addToCart() {
var items = FillArray();
var that = this;
var ul = document.getElementById("list");
for (var i = 0; i < items.length; i++) {
var li = document.createElement("li");
li.id = 'li' + items[i].index;
var currentItem = items[i];
for (p in currentItem) {
var div = document.createElement("div");
if (p.valueOf() == "picURL") {
div.innerHTML = "<img class='miniPic' src='" + currentItem[p].valueOf() + "'/>";
}
else if (p.valueOf() == "price") {
div.innerHTML = p.valueOf() + " : £" + currentItem[p].valueOf();
}
else {
div.innerHTML = p.valueOf() + " : " + currentItem[p].valueOf();
}
li.appendChild(div);
}
}
但是,当我调用视图此答案是我得到:
GET /Home/Content/img/gnome7.PNG 404(找不到)
我试图改变文件的位置,路径,但似乎没有任何工作,这是同样的情况,当我尝试在我的项目中本地调用json文件,它也说我无法找到,所以我认为它可能是我的视觉工作室的一种配置,但我无法使其工作,有人可以帮我吗?这是很烦人:(
非常感谢您的回答@Blachshma,是的,这些文件包含在解决方案中,并且我已经完成了该建筑并再次运行,但仍未找到图像 – cacharry
您输入的URL是什么浏览器?因为我看到你试图去'/首页/内容/ IMG/gnome7.PNG'而不是'/Content/img/gnome7.PNG 404' - 这可能是问题... – Blachshma