Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81989

Problem with simple SSP page

$
0
0

Have a very simple page / datatable I'm trying to get going. Basically no editor functions, and just want to grab some data from a table and display within a datatable. I've done more complex ones with Editor involved but this is stumping me (has to be something easy)

Ideally, I'd want to use something in the ssp script to generate the table headers dynamically like I do with columns and specifying the title option, but this is the next problem to solve. For now I can make a static <thead> and <th> entries.

No matter what I try, I get the invalid JSON error.

When I use debugging tools as mentioned in DataTables Technotes I don't see what you'd expect. In most of my pages with DT/Editor, when I do the XHR and look I see the request to ajax_*.php for that page and can click the response and see the JSON.

In this example, when I narrow to XHR requests, I see main.php?_=1512509393433 and when looking at the response i see the actual source for main.php.

This is my Server Side script:

ajax_swData.php

<?php

//error_reporting(E_ALL);
//ini_set("display_errors", 1);

// DataTables PHP library
include( "../../php/DataTables.php" );
require_once("../_includes/functions_global.php");
sec_session_start();

// set the timezone
date_default_timezone_set('America/Chicago');

// DB table to use
$table = 'licenses2';

// Table's primary key
$primaryKey = 'id';

// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
    array( 'db' => 'submitted_by', 'dt' => 'Name' ),
    array( 'db' => 'department',  'dt' => 'Dept'    ),
    array( 'db' => 'software_name',   'dt' => 'Software' ),
    array( 'db' => 'machines',     'dt' => 'UM Property #' )
    );

$sql_details = array(
    'user' => $globalConfig['sw_sqluser'],
    'pass' => $globalConfig['sw_sqlpass'],
    'db'   => $globalConfig['sw_sqldb'],
    'host' => $globalConfig['sw_sqlhost']
);


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * If you just want to use the basic configuration for DataTables with PHP
 * server-side, there is no need to edit below this line.
 */

require_once ( '../_includes/ssp.class.php' );

echo json_encode(
    SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
    );


?>

The HTML is main.php

<?php
require_once ("../_includes/global_header.php");
// GCAC Admin Template page built on Bootstrap


?>

<!-- Page Content -->
<div id="page-wrapper">

    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">TESTING</h3>
                <div class="panel panel-primary">

                    <div class="panel-heading">Software Information</div>
                    <div class="panel-body">

                        <div class="dataTable_wrapper">
                            <table width="100%"
                                class="table table-striped table-bordered table-hover"
                                id="swData">
                                <thead>
                                    <tr>
                                        <th>Name</th>
                                        <th>Dept.</th>
                                        <th>Software</th>
                                        <th>UM Property #</th>
                                    </tr>
                                </thead>
                            </table>
                        </div>
                    </div>

                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
        </div>
        <!-- /.container-fluid -->
    </div>
    <!-- /#page-wrapper -->

<?php require_once("../_includes/global_footer.php"); ?>

<script type="text/javascript">


$(document).ready(function() {

    $('#swData').DataTable( {
        dom: "lfrt",
        ajax: {
            "processing": true,
            "serverSide": true,
            "ajax": "ajax_swData.php"
        },
        "lengthMenu": [ [20, 25, 50, -1], [20, 25, 50, "All"] ],
    } );

} );
</script>

All in all, pretty simple, you'd think. I am including Datatables.php form my `global_header.php' file so it's available everywhere.

Any ideas much appreciated.

N


Viewing all articles
Browse latest Browse all 81989

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>