我有以下代码:
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
function loadPhotos(folderName){
var folder = "assets/photos/"+folderName+"/";
$.ajax({
url : folder,
success: function (data) {
$(data).find("a").attr("href", function (i, val) {
if( val.match(/\.(jpe?g|png|gif)$/) ) {
$("body").append( "<img src='"+ folder + val +"'>" );
}
});
}
});
}
</script>
</head>
<html>
<div onclick="loadPhotos('7thAnnual')">7th Annual</div>
</html>
由于某些奇怪的原因,当我单击div时,loadPhotos函数在ajax调用上引发了404 not found错误...。但是它说找不到的目录确实存在。
作为记录,我在localhost(http://127.0.0.1:8020/)上运行它。
目录结构为Ljf / assets / photos / 7thAnnual ....
因此完整路径为http://127.0.0.1:8020/Ljf/assets/photos/7thAnnual
7thAnnual目录保存所有图像
有什么想法吗?
好的...。看来我必须完全限定网址中的名称,如下所示:
var folder = "127.0.0.1:8020/Ljf/assets/photos/7thAnnual";
而不是仅仅使用:
var folder = "Ljf/assets/photos/7thAnnual"
这个答案带来了
“仅协议方案支持跨源请求:http,数据,chrome,chrome扩展名,https,chrome-extension-resource。”
这是与本帖子不同的问题,但确实解决了
找不到404
所以我将其标记为答案
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句