the javascript parameter is not recognized by the php query

0
function prueba(){
    var prueba=2;
    // var usu=document.getElementById("usu").innerHTML;
    $.getJSON("json/ingresar.php", {prueba:prueba}, function(resulta){
        var valor = JSON.stringify(resulta);
        valor2 = JSON.parse(valor);
        console.log("se supone que ago algo" + valor);
    });
}

I have that function in JavaScript and I would like the usu to send it to a query in PHP but it does not work.

function prueba(){
    //var prueba=2;
    var usu=document.getElementById("usu").innerHTML;
    $.getJSON("json/ingresar.php", {usu:usu}, function(resulta){
        var valor = JSON.stringify(resulta);
        valor2 = JSON.parse(valor);
        console.log("se supone que ago algo" + valor);
    });
}

After that, the test value is changed to the user's value. Obviously, the value of usu will be extracted with the inner.html , it will not be affected if the test value is integer and the other is with text.

In my block PHP I have it like this:

<?php
    include '../Conexion_DB.php';
    $c = new Conexion_DB();
    $conn = $c->__constructor();
    $zona = $_GET["prueba"];
    $sql = 'select Mesa, Descripcion, Estado from cfg_Mesas where Area = '.$zona.' and Mesa > 0 ';
    $stmt = sqlsrv_query($conn, $sql);
    if( $stmt === false) {
    } else {
        while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ){
            datos[]=array("mesa"=>$row["Mesa"],"descripcion"=>$row["Descripcion"],
"estado"=>$row["Estado"]);
        }
        echo json_encode($datos, JSON_UNESCAPED_UNICODE);
    }
?>

Already in my intefaz I already have the button that commands the execution of the function:

<input type="button" name="" value="enviar" onclick="prueba()"/>
    
asked by costadark1212 02.08.2018 в 16:06
source

0 answers