In a Leaflet map, I’m calling a WFS layer from Geoserver containing multiple polylines whith data associated stored in a PostGIS table (geometry, ...) with AJAX.

Everything works fine to dispaly the layer on my map.

Now, I want to be able to delete, edit, create polylines from my layer and display the layer again after modification on my map.

To do it, I’m using AJAX and PHP to delete lines in my postGIS table for exemple. It also works.

Then, after modification in the table, I’m calling my layer another time with AJAX to show on my map the layer modified. For that, in the success of my AJAX which sendind my PHP file, I’m calling another time my WFS layer with AJAX.

It works when i’m deleting a polyline, but, if I want to delete another one, I have a problem with the callback and the console returns : Uncaught TypeError: callEPhaut is not a function

I don’t understand what is happening and I’m not very well with AJAX, JSONP, ...,

Here is my code :

var defaultParametersEPhaut = {
    service : 'WFS',
    version : '1.0.0',
    request : 'GetFeature',
    typeName : 'city:reseau_haut_service',
    outputFormat : 'text/javascript',
    format_options : 'callback:callEPhaut', 
    srsName : 'EPSG:4326',

var parametersEPhaut = L.Util.extend(defaultParametersEPhaut);

var ajaxEPhaut = $.ajax({
    url : owsrootUrlAssainissement + L.Util.getParamString(parametersEPhaut),
    dataType : 'jsonp',
    jsonp: false,
    jsonpCallback: 'callEPhaut',
    success : EPhaut

function EPhaut (reseauEPhaut) {
    conduites_EPhaut = new L.geoJson(reseauEPhaut, { 
            style : styleEPhaut,
            onEachFeature: eachfeatureEPhaut 

function styleEPhaut (feature){
    return {
        color: '#0b0ec3',
        fillColor: '#0b0ec3',
        opacity: 1,
        weight: 3

function eachfeatureEPhaut (feature, layer) {

                layer.on('editable:enable',function (e) {  
                        type = e.layerType,
                        layer = e.layer;
                        vid = this.feature.id.substring(20,24);

                        //on click on a button, it send the php file with Ajax to delete the polyline selectionated

                                        type: 'POST',
                                        data: {gid : vid},
                                        cache: false,
                                        success : function(data) {
                                            map.removeLayer(conduites_EPhaut); //I remove my layer 
                                            //Here I'm calling again my layer to display the modifications                                                
                                                url : owsrootUrlAssainissement + L.Util.getParamString(parametersEPhaut),
                                                dataType : 'jsonp',
                                                jsonp: false,
                                                jsonpCallback: 'callEPhaut',
                                                cache: false,
                                                success : EPhaut,
                                                complete: function(){


And my php file :


// Parametre de  connection  
$host = 'localhost';
$database = 'metier';
$user = '';
$pass = '';
$port = '5432';

$dns = 'pgsql:host='.$host .';port='.$port .';dbname='.$database;

// récupération des variables

$gid = $_POST['gid'];

    $bdd = new PDO("pgsql:host=$host;dbname=$database",$user,$pass);

//Requete d'insertion

$req = $bdd->prepare('DELETE FROM city.reseau_haut_service WHERE gid = ?');



catch(Exception $e)
    echo "Connection a la BDD impossible : ", $e->getMessage();


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.