DataTables json parsing error

This is a common question and I have researched all the answers Google can provide so I apologize for asking it again.

Firebug shows the response as

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

{ "aaData" : [ [ "A",
        "0.67",
        "0.66",
        "0.66",
        "0.66",
        "0.78",
        "1.52",
        "0.00",
        "0.00",
        "-15.38",
        "1970-01-01"
      ],
      [ "AA",
        "0.11",
        "0.12",
        "0.12",
        "0.14",
        "0.12",
        "-8.33",
        "0.00",
        "-14.29",
        "16.67",
        "2013-04-08"
      ],
      [ "AACC",
        "0.03",
        "0.04",
        "0.04",
        "0.04",
        "0.10",
        "-25.00",
        "0.00",
        "0.00",
        "-60.00",
        "2013-03-04"
      ],
      [ "AAN",
        "0.50",
        "0.50",
        "0.50",
        "0.50",
        "0.49",
        "0.00",
        "0.00",
        "0.00",
        "2.04",
        "2013-02-04"
      ],
      [ "AAON",
        "0.23",
        "0.23",
        "0.22",
        "0.22",
        "0.20",
        "0.00",
        "4.55",
        "0.00",
        "10.00",
        "2013-03-11"
      ],
      [ "AAP",
        "0.76",
        "0.76",
        "0.76",
        "0.76",
        "0.76",
        "0.00",
        "0.00",
        "0.00",
        "0.00",
        "2013-02-07"
      ],
      [ "AAPL",
        "13.42",
        "13.34",
        "13.30",
        "13.34",
        "15.45",
        "0.60",
        "0.30",
        "-0.30",
        "-13.66",
        "2013-01-    23"
      ]
    ],
  "iTotalDisplayRecords" : "7",
  "iTotalRecords" : "7",
  "sEcho" : 1
}

jsonlint.com says the the json is valid, but why has apache put the Doctype in front of the response? Is this causing the error?

Firebug also reports the headers as :

Connection  Keep-Alive
Content-Length  798
Content-Type    application/json
Date    Wed, 23 Jan 2013 09:18:35 GMT
Keep-Alive  timeout=5, max=100
Server  Apache/2.2.22 (Ubuntu)
X-Powered-By    PHP/5.4.6-1ubuntu1.1

I am using the server_processing.php script from DataTables with

header('Content-Type: application/json');
echo $output;

The relevant part of my php is:

    $(document).ready(function() {
                $('#example').dataTable( {
                    "bProcessing": true,
                    "bServerSide": true,
                    "sAjaxSource": "server_processing.php",
                    "sPaginationType": "full_numbers"
                } );
            } );
        </script>
    </head>
    <body>
    <div id="dynamic">
    <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
    <thead>
        <tr>
            <th>Symbol</th>
            <th>Current Estimate</th>
            <th>7 days ago</th>
            <th>30 days ago</th>
            <th>60 days ago</th>
            <th>90 days ago</th>
            <th>% Change Current</th>
            <th>% Change 7</th>
            <th>% Change 30</th>
            <th>% Change 60</th>
            <th>Next Earnings Date</th></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td colspan="10" class="dataTables_empty">Loading data from server</td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <th>Symbol</th>
            <th>Current Estimate</th>
            <th>7 days ago</th>
            <th>30 days ago</th>
            <th>60 days ago</th>
            <th>90 days ago</th>
            <th>% Change Current</th>
            <th>% Change 7</th>
            <th>% Change 30</th>
            <th>% Change 60</th>
        </tr>
    </tfoot>
   </table>

I've lost many hours trying to solve this so am very grateful for any help.

Answers


I found my issue. I had a prepend function that was adding the doctype. Once removed, everything was fine. I found it by moving my code to another development site without the prepend and it worked.


Need Your Help

PHP considers P == 0

php types conditional

This is absolute insanity. I was testing a post variable today that should always evaluate to a single character. Example code is...

Dynamic Shared Object equivalent on windows

windows object dynamic dll shared

The Dynamic Shared Object library on Linux is approximately equal the dll in Windows. That's what I found online. But there are some differences and they are explained here: Architecturally what is...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.