In the Editor, how to ajax communicate from table.*.js to table.*.php
In the Editor, how to ajax communicate from table.*.js to table.*.php
The following files were produced form Generator with some of my modifications.
When trying to use ajax (table.Unit.js) to communicate to the receiving server (table.Unit.php) using "data:", the associated $_POST in the php is empty. In fact when I log all of $_POST, it all appears to be empty (see the log instructions in table.Unit.php file). Below are code from each js and php file:
What I am trying to accomplish is:
1) allow a user to select a DBID value (my test case below, jams a 62612540 into "data:")
2) and pass that value through the client table.Unit.js to server table.Unit.php through $_POST
3) where it will be part of the ->where('DBID',$TempDBID) to return the associated record for CRUD.
Can anyone help to confirm that I should be able to communicate in this manner. And the $_POST['PRAM_DBID] approach should work?
Program table.Unit.js
/*
* Editor client script for DB table Unit
* Created by http://editor.datatables.net/generator
*/
(function($){
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
serverSide: true,
ajax: 'php/table.Unit.php',
table: '#Unit',
data:{"PRAM_DBID":62612540}, // setting the PRAM_DBID for testing. DBID is an int(11)
fields: [
{
"label": "Name:",
"name": "Name",
"className": 'full'
},
Program table.Unit.php
<?php
/*
* Editor server script for DB table Unit
* Created by http://editor.datatables.net/generator
*/
// DataTables PHP library and database connection
$output = var_export($_POST, true);
error_log($output);
$TempDBID = 0;
if (isset($_POST['PRAM_DBID'])){
$TempDBID=$_POST['PRAM_DBID'];
}
include( "lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'Unit', 'DBID' )
->fields(
Field::inst( 'Name' ),
Field::inst( 'Sequence' ),
Field::inst( 'Course_DBID' ),
Field::inst( 'Account_DBID' ),
Field::inst( 'Description' ),
Field::inst( 'Description_HTML' ),
Field::inst( 'ShortDescription' ),
Field::inst( 'Category_1' ),
Field::inst( 'Category_2' ),
Field::inst( 'ID' ),
Field::inst( 'CreateDate' )
->validator( 'Validate::dateFormat', array( 'format'=>'Y-m-d H:i:s' ) )
->getFormatter( 'Format::datetime', array( 'from'=>'Y-m-d H:i:s', 'to' =>'Y-m-d H:i:s' ) )
->setFormatter( 'Format::datetime', array( 'to' =>'Y-m-d H:i:s', 'from'=>'Y-m-d H:i:s' ) ),
Field::inst( 'CreateUser' ),
Field::inst( 'UpdateDate' )
->validator( 'Validate::dateFormat', array( 'format'=>'Y-m-d H:i:s' ) )
->getFormatter( 'Format::datetime', array( 'from'=>'Y-m-d H:i:s', 'to' =>'Y-m-d H:i:s' ) )
->setFormatter( 'Format::datetime', array( 'to' =>'Y-m-d H:i:s', 'from'=>'Y-m-d H:i:s' ) ),
Field::inst( 'UpdateUser' ),
Field::inst( 'DBID' )->set(false)
)
->where('DBID',$TempDBID) // this is the test to use DBID in the "WHERE"
->process( $_POST )
->json();