How to update the data with the button instead of the blur

0

How I have a huge doubt, I have my table and now I update the data and all I need is to do it by pressing a button and NOT by clicking outside the table with blur. I leave my code, Thank you.

<script src="../../js/jquery-3.3.1.min.js"></script>
    <script>
    //OBTENIENDO DATOS
    $(document).ready(function() {

        function obtener_datos(){
            $.ajax({

                url: "mostrar_datos.php",
                method: "POST",
                success: function click(data){
                    $("#result").html(data)
                }
            })

        }

        obtener_datos();
        //OBTENIENDO DATOS

        //ACTUALIZANDO DATOS
        function actualizar_datos(id,texto,columna){
             $.ajax({

                url: "actualizar.php",
                method: "POST",
                data: {id: id, texto:texto, columna:columna},
                success: function(data){
                    obtener_datos();
                    alert(data)
                }
            })

        }



        $(document).on('click', '#nombre_usuario',function(){
            var id = $(this).data("id_usuario");
            var nombre = $(this).text();

            actualizar_datos(id,nombre,"nombres");

        })

        $(document).on("blur", "#mate",function(){
            var id = $(this).data("id_mate");
            var mate = $(this).text();

            actualizar_datos(id,mate,"matematicas1");
        })
        //ACTUALIZANDO DATOS
});

    </script>



  $consulta=mysql_query("SELECT * FROM user");

  echo "
  <table border='1px' align='center'>
     <tr>
        <th>No.</th>
        <th>Nombre</th>
        <th>Matematicas</th>
     </tr>
  ";

  while ($registro = mysql_fetch_array($consulta)) {
    echo "
    <tr>
        <td>".$registro["user_id"]."</td>
        <td id='nombre_usuario' data-id_usuario= '".$registro["user_id"]."'contenteditable>".$registro["nombres"]." </td>
        <td id='mate' data-id_mate= '".$registro["user_id"]."'contenteditable>".$registro["matematicas1"]."</td>
</tr>";
  }
  echo "</table>";
   ?>
    
asked by Ivan Cazares 11.07.2018 в 22:16
source

1 answer

0

Well I would do it in the following way:

$("#nombre_usuario").click(function(){
       var id = $(this).data("id_usuario");
        var nombre = $(this).text();
        actualizar_datos(id,nombre,"nombres")
});

For what happened in the selector click event.

    
answered by 11.07.2018 в 23:22