Put Alert of confirmation in this code

0

Hello, someone could help me how to put an alert that first tells me if you want to confirm whether or not in this code

THIS IS MY JAVASCRIPT

 function Fagregartecins_inc_67(){
        //alert("Incumplió rta1");
            tec_inc_id_tecnicos_67 = $('#txt_tec_ins_inc_67 ').val();
            tec_inc_id_pregunta_67 = 67 //$('#txt_tec_inc_id_pre_2').val();
            if(tec_inc_id_tecnicos_67 == '' || tec_inc_id_tecnicos_67    == null){
                alert('Debe seleccionar un técnico.');
                return;
            }

            var datosTecInc1 = {
                    tec_inc_id_tecnicos         : tec_inc_id_tecnicos_67,
                    tec_inc_id_pregunta         : tec_inc_id_pregunta_67
                };

            //alert("agregando tecnico..."  + tec_inc_id_tecnicos_1); 
            $.post('php/agregartecinc.php', datosTecInc1, function(data, textStatus, xhr) {
                    //alert("Procesando...");
                    if (data == 0){
                        alert('No se pudo procesar. Intente mas tarde.');
                        return;
                    }
                    if (data == 2){
                        alert('No se ha ingresado el técnico a la inspeccion.');
                        return;
                    }
                    if (data == 3){
                        alert('No se pudo procesar. Error al insertar.');
                        return;
                    }
                    if (data == 5){
                        alert('Cedula de tecnico no encontrada.');
                        return;
                    }
                    if (data == 1){
                        //alert('Se ha guardado correctamente el registro: ' + data);
                        alert('Se ha guardado correctamente el registro.');
                        $.post('php/cuadrilla_actualiza.php', datosTecInc1, function(data2, textStatus, xhr) {
                            //alert(data2);
                            $('#datoscuadrilla').html(data2);
                        });
                        return;
                    }
                    alert('Error:' + data);

            }); 
        return;
    }

and my insert

$tec_inc_id_tecnicos        = addslashes($_POST['tec_inc_id_tecnicos']);
$tec_inc_id_pregunta        = addslashes($_POST['tec_inc_id_pregunta']);
//echo $tec_inc_id_tecnicos . '_' .$tec_inc_id_pregunta;
//die();
if (!empty($_POST)){ 
        if ($_SESSION['id_contrato'] == null or $_SESSION['id_contrato'] == '' or $_SESSION['id_inspeccion'] == null or $_SESSION['id_inspeccion'] == ''){ 
            echo 2; //No se tiene variable id_contrato/id_inspeccion
            //die();
        }
        else {
            //echo 1;

            // cedula tecnico
            $sql_tec = "SELECT 
                id_tecnicos
            FROM 
                tecnicos
            WHERE
                cedula = '$tec_inc_id_tecnicos';";

            $con = Conectar();
            $resultado_tec = $con->query($sql_tec);

            /* Recuperar y almacenar en conjunto los resultados de la consulta.*/
            $idx = 0;

            $Resultados_tec = array();

            while ($row_tec = mysqli_fetch_assoc($resultado_tec)) {
                $Resultados_tec[$idx] = array();
                $Resultados_tec[$idx]['id_tecnicos']    = utf8_encode($row_tec['id_tecnicos']);
                $idx++;
            }
            if ( $idx == 0){
                echo 5;
                die();
            } 

            // fin cedula tecnico
            $sql =   "INSERT INTO  tecnico_incumplimientos (id_tecnicos , id_pregunta,id_inspeccion) 
                            VALUES (".$Resultados_tec[0]['id_tecnicos'].",".$tec_inc_id_pregunta."," .$_SESSION['id_inspeccion'] .")";
            $con = Conectar();

            $con->query(utf8_decode($sql));

            if ( $con->affected_rows > 0){
                $nuevoId = $con->insert_id;
                echo 1;
                //echo $nuevoId;
            } 
            else{
                echo 3 . $sql;
            }
        }
}
else{ 
    echo 0;
}
?>
    
asked by JSACTM Music 25.09.2018 в 14:51
source

2 answers

0

You can use the confirm() , I'll give you a short example and then I enter it in your code JS :

function myFunction() {
  if(confirm("Desea guardar los datos?")){
    alert("Datos guardados exitosamente");
  }else{
    alert("Usted cancelo la acción para guardar");
  }
}
<button onclick="myFunction()">Probar</button>

With your JS code:

function Fagregartecins_inc_67(){
  
  if(confirm("Deseas guardar los datos?")){
  
            tec_inc_id_tecnicos_67 = $('#txt_tec_ins_inc_67 ').val();
            tec_inc_id_pregunta_67 = 67 //$('#txt_tec_inc_id_pre_2').val();
            if(tec_inc_id_tecnicos_67 == '' || tec_inc_id_tecnicos_67    == null){
                alert('Debe seleccionar un técnico.');
                return;
            }

            var datosTecInc1 = {
                    tec_inc_id_tecnicos         : tec_inc_id_tecnicos_67,
                    tec_inc_id_pregunta         : tec_inc_id_pregunta_67
                };

            //alert("agregando tecnico..."  + tec_inc_id_tecnicos_1); 
            $.post('php/agregartecinc.php', datosTecInc1, function(data, textStatus, xhr) {
                    //alert("Procesando...");
                    if (data == 0){
                        alert('No se pudo procesar. Intente mas tarde.');
                        return;
                    }
                    if (data == 2){
                        alert('No se ha ingresado el técnico a la inspeccion.');
                        return;
                    }
                    if (data == 3){
                        alert('No se pudo procesar. Error al insertar.');
                        return;
                    }
                    if (data == 5){
                        alert('Cedula de tecnico no encontrada.');
                        return;
                    }
                    if (data == 1){
                        //alert('Se ha guardado correctamente el registro: ' + data);
                        alert('Se ha guardado correctamente el registro.');
                        $.post('php/cuadrilla_actualiza.php', datosTecInc1, function(data2, textStatus, xhr) {
                            //alert(data2);
                            $('#datoscuadrilla').html(data2);
                        });
                        return;
                    }
                    alert('Error:' + data);

            }); 
        return;
       }
    }
<button onclick="Fagregartecins_inc_67()">Probar</button>

I hope you serve, greetings.

    
answered by 25.09.2018 / 15:29
source
0

You can use the window.confirm method which:

  

Displays a dialog window with an optional message and two buttons,   Accept and Cancel.

For example:

if (window.confirm("¿Realmente quieres realizar esta acción?")) {
  console.log("Aquí todo lo relativo a Sí");
} else {
  console.log("Aquí todo lo relativo a No");
}

Example of use in your code

                if (data == 1){
                    //alert('Se ha guardado correctamente el registro: ' + data);
                    alert('Se ha guardado correctamente el registro.');

                   if (window.confirm("¿Quieres lanzar el post?")) {
                        $.post('php/cuadrilla_actualiza.php', datosTecInc1, function(data2, textStatus, xhr) {
                        //alert(data2);
                        $('#datoscuadrilla').html(data2);
                    });
                   } else {
                        console.log("Dijiste que no cancelando");
                   }

A lot of attention to this

It's interesting what the note says about this method in MDN in the section > Notas :

  

Dialog boxes are modal windows - this prevents the user   continue accessing the rest of the program interface until the   modal window has been closed. For this reason it should not be used in   Excessive functions that create dialog boxes (or modal windows). Do not   However, there are very good reasons for avoid using boxes of   Dialog for confirmations .

     

Users of Mozilla Chrome users (eg Firefox extensions)   should use nsIPromptService methods instead of boxes of   dialogue.

     

As of version 46.0 of Chrome, this method is blocked within   of a unless the sandbox attribute has the value   allow-modal.

     

The argument is optional and not required by the specification.

Dialog boxes are used less and less in programming.

    
answered by 25.09.2018 в 15:22