copy table record to another ajax and php

1

I have the following function which receives an id as parameter:

function terminar_tramite(ids) {

    var ID = ids;
    console.log(ID);
    $.ajax({
        url: "lib/controladores/tramite_terminado.php",
        type: 'POST',
        data: 'idss=${ID}',
        contentType: false,
        processData: false,
        success: function(response){
            if (response.success) {
               console.log("no está guardando")
                UIkit.notification({
                    message: 'Ocurrió un error!',
                    status: 'primary',
                    pos: 'top-right',
                    timeout: 5000
                });
            }else{
                UIkit.notification({
                    message: 'Tramite Guardado!',
                    status: 'success',
                    pos: 'bottom-center',
                    timeout: 5000
                });
                setTimeout(function(){
                    location.href = '?sub=adm&op=tablero_tramites';
                },2000);
                setTimeout(function(){
                location.href = '?sub=adm&op=tablero_tramites';
                },2000);
            }
        }
    })
}

My PHP code:

    <?php
    include '../../config.php';
    $dbserver = DB_SERVER;
    $dbuser = DB_USER;
    $password = DB_PASS;
    $dbname = DB_NAME;
    $database = new mysqli($dbserver, $dbuser, $password, $dbname);
    $variable = $_POST['idss'];
    var_dump($variable);
    if($database->connect_errno) {
        die("No se pudo conectar a la base de datos");
    }
    $insertquery  = " INSERT INTO tramites_atendidos SELECT * FROM tramites WHERE tr_id = '$variable'";
    $jsondata = array();
    if($database->query($insertquery)){
    }
    else {  
    }
    $database->close();
?>

I just do not get the id or I would not know if I'm adding it correctly in my Query because if I put the id directly if it copies the record

    
asked by arglez35 10.04.2018 в 20:44
source

2 answers

3

Only correct the syntax a bit when sending the id data:

function terminar_tramite(ids) {

    var ID = ids;
    console.log(ID);
    $.ajax({
        url: "lib/controladores/tramite_terminado.php",
        method:'POST',
        data: {"idss": ID}, //Cambiar esta linea
       //contentType: false, -> Eliminar
       //processData: false, -> Eliminar
        success: function(response){
            if (response.success) {
               console.log("no está guardando")
                UIkit.notification({
                    message: 'Ocurrió un error!',
                    status: 'primary',
                    pos: 'top-right',
                    timeout: 5000
                });
            }else{
                UIkit.notification({
                    message: 'Tramite Guardado!',
                    status: 'success',
                    pos: 'bottom-center',
                    timeout: 5000
                });
                setTimeout(function(){
                    location.href = '?sub=adm&op=tablero_tramites';
                },2000);
                setTimeout(function(){
                location.href = '?sub=adm&op=tablero_tramites';
                },2000);
            }
        }
    })
}
    
answered by 10.04.2018 / 20:51
source
1

Try changing the sending of the variable in your data in this way:

data: {
   "idss": ID
},
    
answered by 10.04.2018 в 20:51