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

0

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('show.bs.modal', function(e) {

                 var $modal = $(this),
                     esseyId = e.relatedTarget.id;

                  DatosGlobales = esseyId;

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

                $modal.find('.edit-content').html(DatosGlobales);      

            }

        });       

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

details.php

    $PostID=$_POST['esseyId'];

    $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 в 14:17
source

1 answer

1

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){

Greetings!

    
answered by 28.11.2016 / 14:24
source