JSON Parse Error

JSON Parse Error

AlawrenceAlawrence Posts: 18Questions: 0Answers: 0
edited March 2011 in General
Again I apologize for asking what may be an incredibly simplistic question but I am stuck. I have a page that is using server side processing and we are trying to use "show and hide details". After much tinkering I went back to the example and still cant get it to work correctly.

On the main page we have
[code]

var oTable;

/* Formating function for row details */
function fnFormatDetails ( nTr )
{
var aData = oTable.fnGetData( nTr );
var sOut = '';
sOut += 'Rendering engine:'+aData[2]+' '+aData[5]+'';
sOut += 'Link to source:Could provide a link here';
sOut += 'Extra info:And any further details here (images etc)';
sOut += '';

return sOut;
}
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "server_processing2.php",
"bJQueryUI": true,
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sSwfPath": "http://192.168.101.40/myfms/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf"
},
"sPaginationType": "full_numbers",
"aoColumns": [
{ "sClass": "center", "bSortable": false },
null,
null,
null,
{ "sClass": "center" },
{ "sClass": "center" }],
"aaSorting": [[1, 'asc']]

} );

$('#example tbody td img').live( 'click', function () {
var nTr = this.parentNode.parentNode;
if ( this.src.match('details_close') )
{
/* This row is already open - close it */
this.src = "../examples_support/details_open.png";
oTable.fnClose( nTr );
}
else
{
/* Open this row */
this.src = "../examples_support/details_close.png";
oTable.fnOpen( nTr, fnFormatDetails(nTr), 'details' );
}
} );
} );

[/code]

Replies

  • AlawrenceAlawrence Posts: 18Questions: 0Answers: 0
    On the Processing Page we have the following:
    [code]
    <?php

    /* Indexed column (used for fast and accurate table cardinality) */
    $sIndexColumn = "id";

    /* DB table to use */
    $sTable = "intake";

    /* Database connection information */
    $gaSql['user'] = "fmed";
    $gaSql['password'] = "ourpass";
    $gaSql['db'] = "Intake";
    $gaSql['server'] = "192.168.101.40";


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

    /*
    * MySQL connection
    */
    $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
    die( 'Could not open connection to server' );

    mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
    die( 'Could not select database '. $gaSql['db'] );

    /* Paging */
    $sLimit = "";
    if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
    {
    $sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
    mysql_real_escape_string( $_GET['iDisplayLength'] );
    }

    /* Ordering */
    if ( isset( $_GET['iSortCol_0'] ) )
    {
    $sOrder = "ORDER BY ";
    for ( $i=0 ; $i
    [/code]

    Every time I get a JSON Parse Error. Once again I know its something simple Im missing.
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    There is something in the return which is breaking the JSON. Try having a look at the server return in Firebug and see what the response says. It might just say that there is an error or something. You can check your JSON in http://jsonlint.com .

    Allan
  • AlawrenceAlawrence Posts: 18Questions: 0Answers: 0
    Allan,

    As expected Firebug sees an error which it reports as:
    [JavaScript Error: "[Exception... "'JavaScript component does not have a method named: "handleEvent"' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x80570030 (NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED)" location: "" data: no]"]

    jsonlint.com seems to say syntax error line 1. However a JSON from a working project also fails when I run it through that validator with the same error.
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Can you give us a link to your site please? I'm not sure what would be causing that error.

    Allan
  • AlawrenceAlawrence Posts: 18Questions: 0Answers: 0
    Allan,

    Unfortunately we are currently running this in somewhat of a sandbox environment so there is no outside connection to it. I do However have this JSON that does work but Doesn't allow me to add the hidden info. Possibly Someone can lead me in the right direction to allow this JSON to perform the Desired function.

    [code]
    <?php

    $aColumns = array('Entry_Date', 'Customer_Name', 'Order_Number', 'Zip_Code', 'Entry_Time', 'Intake_Initials' );

    /* Indexed column (used for fast and accurate table cardinality) */
    $sIndexColumn = "id";

    /* DB table to use */
    $sTable = "intake";

    /* Database connection information */
    $gaSql['user'] = "fmed";
    $gaSql['password'] = "ourpass";
    $gaSql['db'] = "Intake";
    $gaSql['server'] = "192.168.101.40";


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

    /*
    * MySQL connection
    */
    $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
    die( 'Could not open connection to server' );

    mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
    die( 'Could not select database '. $gaSql['db'] );


    /*
    * Paging
    */
    $sLimit = "";
    if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
    {
    $sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
    mysql_real_escape_string( $_GET['iDisplayLength'] );
    }


    /*
    * Ordering
    */
    if ( isset( $_GET['iSortCol_0'] ) )
    {
    $sOrder = "ORDER BY ";
    for ( $i=0 ; $i $iFilteredTotal,
    "aaData" => array()
    );

    while ( $aRow = mysql_fetch_array( $rResult ) )
    {
    $row = array();
    for ( $i=0 ; $i
    [/code]
  • AlawrenceAlawrence Posts: 18Questions: 0Answers: 0
    Although this works Firebug reports the same JavaScript error.
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Googling for that error it looks like it might be caused by a Firefox plug-in. I'd suggest trying 'Inspector' in Chrome / Safari and see if that says anything useful and also updating all Firebug plug-ins.

    You noted that this works now - cool :-)

    Allan
This discussion has been closed.