$.ajax({
url:"https://xxxxxxxxx/resource/default/static/data/mapdata.json",
dataType:"json",
type:"get",
success:function(data){
//data就是json文件中的数据
.......
},
error: function (err) { // 如果执行不成功,那么执行此方法
console.log(err)
}
})
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
注意 url 不能写成 ../../resource/default/static/data/mapdata.json 这种形式,这种url拿不到数据
如果已经部署到线上了,可以用域名加文件路径,没有的话就http://localhost:8080/resource/default/static/data/mapdata.json 这种方式拿
localhost可以改成ip地址,8080端口改成自己项目的端口