【发布时间】:2017-01-06 08:27:07
【问题描述】:
我正在尝试从文件中加载 json 对象.. 但它总是会出现错误消息
<html>
<head>
<title>The jQuery Example</title>
<script type = "text/javascript"
src = "http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
$("#driver").click(function(event){
$.ajax({
url: 'file.json',
type: 'get',
dataType: 'json',
error: function(data){
$('#stage').html("error");
},
success: function(data){
$('#stage').html("ay 7aga");
}
});
});
});
</script>
</head>
<body>
<p>Click on the button to load result.html file:</p>
<div id = "stage">
STAGE
</div>
<input type = "button" id = "driver" value = "Load Data" />
</body>
</html>
还有我的file.json
{"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}
这是文件位置
关于成功消息的任何建议?
它说Failed to load resource: the server responded with a status of 404 (Not Found)
请帮助我是初学者 任何建议请..提前谢谢
【问题讨论】:
-
在我看来,您将 json 文件放置在错误的位置。我假设您拥有 index.html 的文件夹是您的网络根目录。所以这就是你的 json 文件需要的地方。假设是一个静态文件服务器。
标签: javascript java jquery json jakarta-ee