1

Hi I am using php to connect to my database. Here is my list action code: the table and database do have the same name

<?php
try
{
    //Open database connection
    $con = mysql_connect("localhost","root","");
    mysql_select_db("702data", $con);

    //Getting records (listAction)
    if($_GET["action"] == "list")
    {
        //Get records from database
        $result = mysql_query("SELECT * FROM 702data;");

        //Add all records to an array
        $rows = array();
        while($row = mysql_fetch_assoc($result))
        {
            $rows[] = $row;
        }

        //Return result to jTable
        $jTableResult = array();
        $jTableResult['Result'] = "OK";
        $jTableResult['Records'] = $rows;
        print json_encode($jTableResult);
    }

and here is my jtable initialization:

<body>
        <div id="DeviceTableContainer"></div>
        <script type="text/javascript">
            $(document).ready(function() {
                $('#DeviceTableContainer').jtable({
                    title: 'Wireless Monitor',
                    actions: {
                        listAction: 'DeviceActions.php?action=list',
                        createAction: 'DeviceActions.php?action=create',
                        updateAction: 'DeviceActions.php?action=update',
                        deleteAction: 'DeviceActions.php?action=delete'
                    },
                    fields: {
                        DeviceId: {
                            key: true,
                            list: false
                        },
                        DeviceTag: {
                            title: 'Device Tag',
                            width: '40%'
                        },
                        PV: {
                            title: 'PV',
                            width: '10%'
                        },
                        SV: {
                            title: 'SV',
                            width: '10%'
                        },
                        Timestamp: {
                            title: 'Timestamp',
                            width: '30%',
                            type: 'date',
                            create: false,
                            edit: false
                        }
                    }
                });
                $('#DeviceTableContainer').jtable('load');
            });

        </script>
    </body>

The error I am receiving is on this line in jQuery.js:

parseJSON: function( data ) {
// Attempt to parse using the native JSON parser first
if ( window.JSON && window.JSON.parse ) {
return window.JSON.parse( data );////////////////////////////////////
}

It looks like it is parsing the entire deviceactions.php file because in firebug the data object has the entire file net to it as a string. I am very new to web dev so it could be something obvious. I am also developing this as a java web application if that matters. Thanks

edit: here is some more information about the error

parseJSON()jquery.js (line 550)
data = "<?php\r\ntry\r\n{\r\n //Open ...TableResult);\r\n}\r\n \r\n?>"
ajaxConvert()jquery.js (line 8447)

s = Object { url="DeviceActions.php?action=list", type="POST", isLocal=false, more...}

response = "<?php\r\ntry\r\n{\r\n //Open ...TableResult);\r\n}\r\n \r\n?>"

jqXHR = Object { readyState=4, responseText="<?php\r\ntry\r\n{\r\n //Open ...TableResult);\r\n}\r\n \r\n?>", getResponseHeader=function(), more...}

isSuccess = true
jeanqueq
  • 123
  • 2
  • 19

1 Answers1

0

Ensure that your server (PHP)marks content-type as JSON when returning the response

Srini
  • 37
  • 1