简体   繁体   中英

How to reload GeoJSON Data if changed in Leaflet map?

I am working on a leaflet map, which contains data from to GEOJSON files. The GeoJSON Database is changing, if somebody makes an entry in a connected form on the web. The form, database and leaflet map are all on the same server. I am loading the JSON-Files in my HTML like this:

        <script src="data/export.json" type="text/javascript"></script>

If the data inside export.json changes, the "new" data does not appear in my leaflet map until I do a hard refresh of the html page with strg+f5.

Is there any way to reload the JSON-File if the data inside has changed? Or do I have to modify my "main.js" where I am loading the GeoJSON data into my layers?

Thanks a lot for all your help.

I've already found the possibility to add a "version" to my JSON-File like this:

        <script src="data/export.json?t=<?=time()?>" type="text/javascript"></script>

It did not work for me.

I've had a hard time with trying different ways to solve it, but the solution is easy:

I changed my.html-file to a.php-file with declaring the Doctype as html. This allows you to use php-Code in the document. As a result the code

<script src="data/export.json?t=<?php echo time(); ?>" type="text/javascript"></script

worked and the browser loads the json-data every time the page reloads (without using the cache).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM