Stuck on processing problem

Stuck on processing problem

melphmelph Posts: 37Questions: 1Answers: 0
edited May 2012 in General
Apologies for this as I know from searching the forum that this problem has been answered many times before. I have followed answers but still cannot get this to work.

[b]The problem: -[/b] DataTable displays "Processing" message despite data successfully retrieved from the server.

1. I am using examples straight out of the zipped download with no alteration to code, other than entering my database details
2. I am using the "server_side.html" page to display the data and "custom_data_property.php" page to retrieve the data from the database
3. If I run the server_side.html page, the table formats correctly, the sortable headers work (as in I know the correct js files are being accessed by the page), but the table data is not displayed, just the "processing "message
4. If I press one of the sortable headers, I can see from the "Server Response" part of the example page (this displays below where the table should be) that a request is sent to the server and that it receives the data back. sEcho aways starts at 1 from the inital load of the page and increments by one on each press of a header sort button
5. If i use the search box and enter a search string, such as "Mark", the "Server Response" section displays all matches of "Mark", but still not displayed in the table
6. I have run the page via JSON lint and shows as valid

Here is a snippet of the data returned, cut and pasted from the "Server Response" part of the page

{
"sEcho": 1,
"iTotalRecords": "442",
"iTotalDisplayRecords": "442",
"test": [
[
"1",
"Mark",
"Elvin",
"Mark Elvin (admin)"
],
// more results follow here //

However, if I view the server script page directly, I get the following result:

[code] {"sEcho":0,"iTotalRecords":"442","iTotalDisplayRecords":"442","test":[["1","Mark","Elvin","Mark Elvin (admin)"],
// more results follow here //

This shows sEcho 0 and not 1 - is this my problem? if so, could someone please point me in the right direction to fix this.

I have spent many hours trying to fix it, but am at a loss as to where to go next.

Best wishes

Mark

HTML and Java looks like this:




$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "custom_data_property.php"
} );
} );






 




user_id
first_name
last_name
user_name





Loading data from server




user_id
first_name
last_name
user_name

Replies

  • melphmelph Posts: 37Questions: 1Answers: 0
    Further reading shows (i think) that the response I receive back from the server doesn't give any indication to dataTables as to where to put the data!

    So, I changed this to now tell datatables the columns to use:-

    $(document).ready(function() {
    $('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "custom_data_property.php",
    "aoColumns": [
    { "mDataProp": "user_id" },
    { "mDataProp": "first_name" },
    { "mDataProp": "last_name" },
    { "mDataProp": "user_name" },

    ]
    } );
    } );

    BUT the PHP file that comes with the example I dont think constructs the request to return these values - this is some of the code:

    $aColumns = array( 'user_id', 'first_name', 'last_name', 'user_name' );

    This was cut from the top of the serverside PHP example script

    The following fro mthe end of the PHP script - this is what I take to be the code for construcing teh JSON request?

    * Output
    */
    $output = array(
    "sEcho" => intval($_GET['sEcho']),
    "iTotalRecords" => $iTotal,
    "iTotalDisplayRecords" => $iFilteredTotal,
    "test" => array()
    );

    while ( $aRow = mysql_fetch_array( $rResult ) )
    {
    $row = array();
    for ( $i=0 ; $i
  • melphmelph Posts: 37Questions: 1Answers: 0
    No longer an issue - sorry I am a newbie and was mixing up page types e.g. not using jsonp.html with jsonp.php etc!!

    Problem solved
This discussion has been closed.