Collect data in modal Bootstrap and retrieve data from PHP at the same time (AJAX, PHP, MySql)


I receive data from a link and show them in a modal Bootstrap

page 1

       <a href="pagina" id="id" data-target="#edit-modal">Enlace</a>

page 2

      $('#edit-modal').on('', function(e) {

                 var $modal = $(this),
                     esseyId =;

                  DatosGlobales = esseyId;

            type: 'POST',
            data: DatosGlobales,
            url: 'detalles.php?jsoncallback=?',
            success: function(data){




It works perfect. I just want to retrieve the details of details.php and show them in that same modal.



    $sql = "SELECT * FROM tabla WHERE id='".$PostID."' ";
    mysqli_set_charset($conexion, "ISO-8859-1"); 
    if(!$result = mysqli_query($conexion, $sql)) die();
    $cursos = array(); 
    while($row = mysqli_fetch_array($result)) 

    $nomEns        =$row['NomEns']; 

    $cursos[] = array('nomEns' => $nomEns);


    $json_string = json_encode($cursos);
    echo $_GET['jsoncallback'] . '(' . $json_string . ');';

How can I show the data returned by php? Any suggestions? Thank you.

asked by rafa_pe 28.11.2016 в 15:17

1 answer


In the success of the ajax call you are setting $modal.find('.edit-content').html(DatosGlobales); the variable DatosGlobales you initialize it before the ajax call, if you want to put what the php returns you should use data which is what returns the function of success

success: function(data){


answered by 28.11.2016 / 15:24