title: Problems with leaflet marker and the 'onclick' event
body: <p>I am using PHP 7, leaflet 1.5.1 and I am looking to call an AJAX when the marker is clicked to display content in a different DIV than the map.</p>
  
  <p>The problem is that the function does not wait for the 'click' and is automatically activated when the page is loaded and shows in the DIV that it listens for the parameter of the last marker.  </p>
  
  <p>And then when I click on a marker, nothing happens, of course</p>
  
  <p>Ideas?</p>
  
  <p>THE SCRIPT</p>
  
  <pre><code>&lt;script src='https://code.jquery.com/jquery-3.4.1.js' integrity='sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=' crossorigin='anonymous'&gt;&lt;/script&gt;
      &lt;script&gt;
       function mostrar2(id){
       var parametro = {id : id};
       $.ajax({
         data: parametro,
         url: 'elphp.php',
         type: 'post',
         beforeSend: function(){$("#panel").html("Thinking...");},
         success: function(response){$("#panel").html(response)}
         });        
       }
      &lt;/script&gt;
  </code></pre>
  
  <p>DIV THAT LISTENS</p>
  
  <pre><code>&lt;div class="col-lg-3" id="panel"&gt;
  </code></pre>
  
  <p>MAP DIV</p>
  
  <pre><code>&lt;div class="col-lg-9 map" id="map" style="width: 400px; height: 400px;"&gt;
   &lt;script&gt;
    var mymap = L.map('map').setView([51.505, -0.09], 13);
    L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
       maxZoom: 18,
       attribution: 'Map data &amp;copy; &lt;a href="https://www.openstreetmap.org/"&gt;OpenStreetMap&lt;/a&gt; contributors, ' +
                  '&lt;a href="https://creativecommons.org/licenses/by-sa/2.0/"&gt;CC-BY-SA&lt;/a&gt;, ' +
                  'Imagery © &lt;a href="https://www.mapbox.com/"&gt;Mapbox&lt;/a&gt;',
       id: 'mapbox.streets'
  }).addTo(mymap);
  
  L.marker([51.5, -0.09]).addTo(mymap).on('click', mostrar2(15741));
  L.marker([51.5, -0.99]).addTo(mymap).on('click', mostrar2('11'));
  
  &lt;/script&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>AND THE PHP</p>
  
  <pre><code>&lt;?php
      $trajo = $_POST['id'];
      echo "YOU SENT : " . $trajo;
  ?&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/YDLw4.png" rel="nofollow noreferrer">This is how it looks</a> </p>