js reads json file data

 $.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>

Note that the url cannot be written in the form ../../resource/default/static/data/mapdata.json. This kind of url cannot get data.

If it has been deployed online, you can use the domain name and file path. If not, use http://localhost:8080/resource/default/static/data/mapdata.json.

localhost can be changed to the IP address, and port 8080 can be changed to the port of your own project

Guess you like

Origin blog.csdn.net/weixin_40841731/article/details/130528826