I am working on created a Leaflet map that has lots and lots of markers. To make keeping the map up to date easier I have all the markers stored in a MySQL database. I have a php file that pulls the data and puts it in a form that javascript can read and then assigns it to a variable.
The problem: I want to then use some method (from what I've been reading AJAX is the safest and best method) to pull the variable from the php file and give it to the .js file to use.
I've read many different questions regarding how to do this and I just can't seem to understand exactly how I use AJAX to pull the variable. I don't know how to do this in Ajax.
Here are some code examples of what i'm trying to do:
get-data.php
//do some php stuff here to pull data
$data = json_encode($datapulledfromDB);
marker.js
//do some ajax here to pull $data
//now here's my javascript that then uses $data
markerLayer = L.geojson(data, {
//e.t.c.
mapindex.php
<script type="text/javascript" src="js/.marker.js"></script>
<script>
map.addLayer(markerLayer);
And just wanted to say that my whole experience creating this map has been wonderful, I've learned a lot and that's mainly because of StackOverflow, I have a problem and I come here and find so many resources that allow me to actually learn what I'm doing wrong. But this problem just has me tearing my hair out!