This is a migrated thread and some comments may be shown as answers.

Problems sending data by POST

1 Answer 208 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Luis
Top achievements
Rank 1
Luis asked on 13 Feb 2012, 08:16 PM
Hi

I'm trying to do a DataSource synchronize with the server, like in the Video
"Get Started With The Kendo UI DataSource".
My Forms works correctly, the grid show me the data correctly and I can Update an Delete well.
The problem is when I send the info from inputs to the file that processes. I'm using PHP and I send the info by POST but I don´t receive anything.

Here´s the code for the inputs, is the same that in the video:


 $(document).ready(function() {
                $("#splitter").kendoSplitter();
                
                dataSource = new kendo.data.DataSource ({
                   transport: {
                       read: {
                           url: "data/instituciones.php"
                       },
                       /*create: {
                           url: "data/instituciones.php",
                           type: "PUT"
                       },*/
                       update: {
                           url: "data/prueba.php",
                           type:"POST"
                       },
                       /*destroy:{
                           type:"DELETE"
                       }*/
                   },
                   schema: {
                       data:"data",
                       model: {
                           id:"id_Inst",
                           fields:{
                               nombre:{validation:{required: true}},
                               tipo:{validation:{required: true}}
                           }
                       }
                   }
                });
                
                var selected;
                
                $("#institucion").kendoGrid({
                    dataSource:dataSource,
                    selectable:true,
                    navigable:true,
                    change: function(){
                        var id = this.select().data("id");
                        selected = this.dataSource.get(id);
                        
                        this.dataSource.options.transport.destroy.url = "data/instituciones" + id;
                        this.dataSource.options.transport.update.url = "data/instituciones" + id;
                        
                        $("#cambiarNombre").val(selected.get("nombre"));
                        $("#cambiarTipo").val(selected.get("tipo"));
                    }
                });
                
                $("#crearInst").click(function(){
                    dataSource.add({nombre: $("#nombreInst").val(), tipo: $("#tipoInst").val()});
                    dataSource.sync();
                    
                    $("#nombreInst").val('');
                    $("#tipoInst").val('');
                    dataSource.read();
                });
                
                $("#update").click(function(){
                    selected.set("nombre", $("#cambiarNombre").val());
                    selected.set("tipo", $("#cambiarTipo").val());
                    dataSource.sync();
                });
                
                $("#delete").click(function(){
                    dataSource.remove(selected);
                    dataSource.sync();
                })
            });
        </script>
    </head>
    <body>
        <div id="wrapper">
            <div id="splitter">
                <div id="left">
                    <div class="inner">
                        <h3>Create</h3>
                        <dl>
                            <dt>Nombre:</dt>
                            <dd><input type="text" id="nombreInst" name="nombreInst"></dd>
                            <dt>Tipo:</dt>
                            <dd><input type="text" id="tipoInst" name="tipoInst"></dd>
                            <dd><button id="crearInst">Crear</button></dd>
                        </dl>
                    </div>
                </div>
                <div id="middle">
                    <div id="rigth-top">
                        <div class="inner">
                            <div id="grid">
                                <table id="institucion">
                                    <tr>
                                        <th data-field="nombre">Nombre</th>
                                        <th data-field="tipo">Tipo</th>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                <div id="right">
                    <h3>Edit</h3>
                    <dl>
                        <dt>Nombre:</dt>
                        <dd><input  type="text" id="cambiarNombre" name="cambiarNombre"/></dd>
                        <dt>Tipo:</dt>
                        <dd><input  type="text" id="cambiarTipo" name="cambiarTipo"/></dd>
                        <dd><span><button id="update">Actualizar</button><button id="delete">Borrar</button></span></dd>
                    </dl>


And the code used in PHP:

<?php
    
    include 'conexion.php';
    header("Content-type: application/json");
    
    $con = conexion();    
    
    $verb = $_SERVER["REQUEST_METHOD"];
    
    if ($verb == "GET") {
    $data = array();
    $query = pg_query($con, "SELECT * FROM \"Institucion\"");
    
    while ($rows = pg_fetch_object($query)) {
        $data[] = $rows;
    }
    
    
    echo "{\"data\":" .json_encode($data). "}";
    }
    
    if ($verb == "POST") {
        
        $id = $_POST["id_Inst"];
        $nombre = $_POST["cambiarNombre"];
        $tipo = $_POST["cambiarTipo"];
        
        $rs = pg_query($con, "UPDATE \"Institucion\" SET nombre = '$nombre' WHERE id_Inst = ".$id) or die(pg_last_error($con));
        
        echo json_encode($rs);
        
    }

?>

The query runs perfectly but in the field "nombre" I dont receive data so I guess that I have problems sending the info from the inputs maybe in the DataSource I dont know.
Someone can help me?

Thanks a lot,
LHGC

1 Answer, 1 is accepted

Sort by
0
Luis
Top achievements
Rank 1
answered on 15 Feb 2012, 08:32 PM
Please Help...I receive "null"  in $id $nombre and $tipo please help
Tags
Data Source
Asked by
Luis
Top achievements
Rank 1
Answers by
Luis
Top achievements
Rank 1
Share this question
or