NEW, EDIT, DELETE successfully but with error Undefined variable data

NEW, EDIT, DELETE successfully but with error Undefined variable data

michelekmichelek Posts: 24Questions: 5Answers: 0

Hi all,

I have this big problem.

I have added in the ajax query an ID to send to the db.php file but with this method datatables give me an error.
What I can do?

This is my code:

dialog.php

<?php
$id = $_REQUEST['id'];
echo $id;
?>

var editor5;
var ids = <?php echo $id; ?>;
$(document).ready(function() {

editor5 = new $.fn.dataTable.Editor( {
   "bServerSide": true,
        ajax: "php/manutenzione2_db.php",
        table: "#example5",
        fields: [ {
                label: "First name:",
                name:  "manutenzione_SUBCAT.id"
            }, {
                label: "Last name:",
                name:  "manutenzione_SUBCAT.nome"
            } , {
        label: "ids",
                name: "manutenzione_SUBCAT.id_manutenzione_CAT2",
                type: 'hidden',
                def: ids
            }
     ]
} );
  
$('#example5').DataTable( {
    dom: "Bfrtip",
  "bServerSide": true,
        ajax: {
            url: "php/manutenzione2_db.php?IDS="+ids,
            type: 'POST'
        },
        columns: [
            { data: "manutenzione_SUBCAT.id" },
            { data: "manutenzione_SUBCAT.nome" }
      
        ],
        select: true,
        buttons: [
            { extend: "create", editor: editor5 },
            { extend: "edit",   editor: editor5 },
            { extend: "remove", editor: editor5 }
        ]
    } );
} );

</script>

<div><p></p></div>
<table id="example5" class="display" cellspacing="0" width="100%">
  <thead>
    <tr>
      <th>ID</th>
            <th>NOME</th> 
      </tr>
  </thead>
    <tfoot>
        <tr>
            <th>ID</th>
            <th>NOME</th>
        </tr>
  </tfoot>
</table>

AND db.php


if (isset($_GET['IDS'])) { $ID_MANUTENZIONE = $_REQUEST['IDS']; } Editor::inst( $db, 'manutenzione_SUBCAT' ) ->field( Field::inst( 'manutenzione_SUBCAT.id' ), Field::inst( 'manutenzione_SUBCAT.nome' ), Field::inst( 'manutenzione_SUBCAT.id_manutenzione_CAT2' ) ) ->where( 'id_manutenzione_CAT2', $ID_MANUTENZIONE) ->process($_REQUEST) ->json();

Replies

  • michelekmichelek Posts: 24Questions: 5Answers: 0

    I found a solution with SESSION but it's not really elegant.

    dialog.php:

    session_start();
    unset($_SESSION['id_manutenzione']);
    $id_manutenzione = $_REQUEST['id'];
    $_SESSION['id_manutenzione'] = $id_manutenzione;
    

    db.php

    session_start();
    Editor::inst( $db, 'manutenzione_SUBCAT' )
        ->field( 
            Field::inst( 'manutenzione_SUBCAT.id' ),
            Field::inst( 'manutenzione_SUBCAT.nome' ),
        Field::inst( 'manutenzione_SUBCAT.id_manutenzione_CAT2' )
        )
      ->where( 'id_manutenzione_CAT2', $_SESSION['id_manutenzione'])
    
    
  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    We discussed this by e-mail also - it looks like you are not submitting the IDS parameter as part of the Editor Ajax request. I would suggest you add that GET parameter to the Ajax URL if you want to successfully use that for both DataTables and Editor Ajax requests.

    Allan

This discussion has been closed.