我正在尝试从文件加载 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"}
]}
这是文件位置
有什么建议可以转到成功消息吗?
它说无法加载资源:服务器响应状态为404(未找到)
请帮助我,我是初学者 任何建议请..提前致谢
最佳答案
尝试使用 url:'../file.json',即对 json 文件的上一级引用
关于javascript - 无法从 .json 文件加载 json 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39220945/