Answer the question
In order to leave comments, you need to log in
How to change json file path in jQuery.getJSON and load new json file?
There are several json files, of which info on Yandex tags is loaded. When you select a city, the map should change.
I thought to do it this way: each city has an attribute that corresponds to the name of the json file. When you click on this city, the path to the json file changes in the script and the map is reloaded from the new json array.
Here is a code snippet:
jQuery.getJSON('/wp-content/uploads/Открытие/1.json', function (json) {
var geoObjects = ym.geoQuery(json)
.addToMap(myMap)
myMap.setCenter(geoObjects.get(0).geometry.getCoordinates());
myMap.setBounds(myMap.geoObjects.getBounds(),{checkZoomRange:true, zoomMargin:9});
});
Answer the question
In order to leave comments, you need to log in
Are the files in order?
i=1;
var path = '/wp-content/uploads/Открытие/'+i+'.json';
function test() {
//code...
i++;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question