salut tt le monde ,
je travaille sur un projet de webmapping vc php et ajax,je dois recuperer un tableau des donnees Geojson dans ajax, ms mon code retourne un tableau vide, il y a que l'entete qui est static et pas les resultats de la requete je vous passe mon code php et JS, si vous voyez il est où l'erreur et merci d'avance
code php
code JSCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 <?php $json = array( 'type' => 'FeatureCollection', 'crs' => array('type'=> 'name','properties'=>array('name'=> 'urn:ogc:def:crs:OGC:1.3:CRS84')), 'features' => array() ); $dbconn = pg_connect("host=localhost dbname=data user=postgres password=ghizlane"); //if(isset($_POST["afficher"])){ $libelle = $_POST['libelle']; $requete = "select equipement,categorie,libelle,ST_AsGeoJSON(the_geom) as geometrie from equipements where libelle = '".$libelle."'"; $result = pg_query($dbconn,$requete); while($row = pg_fetch_assoc($result)){ $infos = $row; unset($infos['geometrie']); $geojson = array( 'type' => 'Feature', 'properties' => $infos, 'geometry' => json_decode($row['geometrie'], true), ); array_push($json['features'], $geojson); } echo json_encode($json); //} ?>
dans php jarrive a recuperer les resultats complets de tableau si sauf dans le code JS qui est videCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 function affichage(){ $.ajax({ url : "affichage.php", dataType: "JSON", jsonpCallback: "getJson", error : function(){ alert("error"); }, success: function(json){ var markers = json.markers.features $(markers).each(function(index,elem){ var lat = elem.geometry.coordinates[0]; var lng = elem.geometry.coordinates[1]; var latlng = L.latLng(lat, lng); var myIcon = L.icon({ iconUrl: 'images/commerces.jpg', iconRetinaUrl: 'images/commerces.jpg', iconSize: [30, 75],}); L.marker(latlng, {icon: myIcon}).addTo(map);}) } }); }