1

I want to populate a datatable from a php call in my $(document).ready function, but I don't want to configure the table for server side processing (I want subsequent sorting/filtering/sorting to happen client side). Below is my current code. Note: I ran the php On the server and pasted the output into a text file. If I use the path to the text file as my url, I get the intended result. So I think that datatables is trying to read my php file as json, and, of course failing. How do I get it to use the output from the php file instead of the php file itself?

Code:

<html>
    <head>
        <title>NCompass Failed Fax Monitor</title>

        <link rel="stylesheet" type="text/css" href="jQuery/datatables.min.css"></link>

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
        <script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
        <script>
            $(document).ready(function() {
                $('#faxList').DataTable({
                    ajax: {
                        url: 'php/Data.php',
                        dataSrc: 'transactions'
                    },
                    columns: [
                        { data: 'PROCESS_DATE' },
                        { data: 'PROCESS_STATUS' },
                        { data: 'PDF_FILE_NAME' },
                        { data: 'REF_ID' },
                        { data: 'ADDITIONAL_INFO' }
                    ]
                });
            });
        </script>
    </head>
    <body>

        <h2>NCompass Failed Fax Monitor</h2>
        <br>

        <table width="100%" class="display" cellspacing="0" id="faxList">
            <thead>
                <tr>
                    <th>Process Date</th>
                    <th>Status</th>
                    <th>PDF File</th>
                    <th>Reference ID</th>
                    <th>Error Description</th>
                </tr>
            </thead>
        </table>
    </body>
</html>
Mark Ainsworth
  • 811
  • 8
  • 24
  • Possible duplicate of [How to manually update datatables table with new JSON data](http://stackoverflow.com/questions/27778389/how-to-manually-update-datatables-table-with-new-json-data) – Xorifelse Jan 25 '17 at 01:47
  • It sounds from your description that you're opening your HTML file locally. Upload the script to your hosting provider and visit the target URL in order for web server to run your PHP script. – Gyrocode.com Jan 25 '17 at 16:31
  • Thanks Fernando, but I may not have been clear: I am running on the web server and I have my php on the server as well. The basic problem is: How do I get the table loaded with the output from the php without specifying that the table is populated server side (I want to populate once from the server and then do other things (filtering / sorting) from the client – Mark Ainsworth Jan 26 '17 at 02:11

0 Answers0