A
A
adron902015-03-09 14:30:32
JavaScript
adron90, 2015-03-09 14:30:32

Why is json not loading?

ymaps.ready(init);

function init () {
    var myMap = new ymaps.Map('map', {
            center: [55.76, 37.64],
            zoom: 10
        }),
        objectManager = new ymaps.ObjectManager({
            clusterize: true,
            gridSize: 32
        });
    objectManager.objects.options.set('preset', 'islands#greenDotIcon');
    objectManager.clusters.options.set('preset', 'islands#greenClusterIcons');
    myMap.geoObjects.add(objectManager);

    $.ajax({
        url: "file:///C:/Users/home/Desktop/json/data.json",
        dataType: "json",
        success: toJsonContainer
    }).done(function(data) {
        objectManager.add(data);
    });

}

why doesn't this code work
$.ajax({
url: "file:///C:/Users/home/Desktop/json/data.json",
dataType: "json",
success: toJsonContainer
}).done(function( data) {
objectManager.add(data);
}
example taken from here Adding objects to the map via ObjectManager
ps. I don't know javascript at all. There was a need to display labels from a json file on a Yandex map.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2015-03-09
@adron90

You can't make AJAX requests to URLs starting with file://. Blablabla security blablabla security same-origin policy, etc, etc, etc. Solution: raise some web server locally.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question