volosoft / jtable

A JQuery plugin to create AJAX based CRUD tables.
http://www.jtable.org
1.1k stars 506 forks source link

TypeError: obj is undefined #1430

Closed kay2000 closed 10 years ago

kay2000 commented 10 years ago

Hi! I'm a newby! I don't know how to format this page! I'm try JTable plugin and I have this strange error. " TypeError: obj is undefined length = obj.length, "

I'm using jquery-1.11.1, jQuery UI - v1.11.0 and the last JTable. This is my page:

           <!doctype html>
           <html>
           <head>
               <meta charset="utf-8">
               <title>Matrimonio di Massimo e Caterina</title>
               <link href="js/themes/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
               <link href="js/scripts/jtable/themes/lightcolor/blue/jtable.css" rel="stylesheet" type="text/css" />
               <script src="js/jquery-1.11.1.js" type="text/javascript"></script>
               <script src="js/jquery-ui/jquery-ui.js"></script>
               <script src="js/scripts/jtable/jquery.jtable.js" type="text/javascript"></script>
           </head>

           <body> 
               <div id="LuoghiTableContainer" style="width: 600px;"></div>
           <br><br><br><br>
           <script type="text/javascript">
               $(document).ready(function () {

                   //Prepare jTable
                       $('#LuoghiTableContainer').jtable({
                               title: 'Table of people',
                               actions: {
                                       listAction: 'LuoghiActions.php?action=list',
                                       createAction: 'LuoghiActions.php?action=create',
                                       updateAction: 'LuoghiActions.php?action=update',
                                       deleteAction: 'LuoghiActions.php?action=delete'
                               },
                               fields: {
                                       Id: {
                                               key: true,
                                               create: false,
                                               edit: false,
                                               list: false
                                       },
                                       idUserMsg: {
                                               title: 'Author id',
                                               width: '20%'
                                       },
                                       message: {
                                               title: 'message',
                                               width: '60%'
                                       },
                                       time: {
                                               title: 'time',
                                               width: '20%'
                                       } 
                               }
                       });

                       //Load person list from server
                       $('#LuoghiTableContainer').jtable('load');

               });    
           </script> 
           </body>
           </html>

And this is LuoghiActions.php:

      try
      {
           //Open database connection
           $con = mysql_connect("localhost","matrimonio_user","orione1180");
           mysql_select_db("matrimonio", $con);

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

                //Add all records to an array
                $rows = array();
                while($row = mysql_fetch_array($result))
                {
                          $row[2] = utf8_encode($row[2]);
                    $rows[] = $row;
                }
                  //Return result to jTable
                  $jTableResult = array();
                  $jTableResult['Result'] = "OK";
                  $jTableResult['Record'] = $rows; //$result;
                  print json_encode($jTableResult);

              }
              else if($_GET["action"] == "create")
           {
                  //Return result to jTable
                  $jTableResult = array();
                  $jTableResult['Result'] = "OK";
                  print json_encode($jTableResult);
              }else if($_GET["action"] == "update")
           {
                  //Return result to jTable
                  $jTableResult = array();
                  $jTableResult['Result'] = "OK";
                  print json_encode($jTableResult);
              }else if($_GET["action"] == "remove")
           {
                  //Return result to jTable
                  $jTableResult = array();
                  $jTableResult['Result'] = "OK";
                  print json_encode($jTableResult);
              }
      }
      catch(Exception $ex)
      {
          //Return error message
           $jTableResult = array();
           $jTableResult['Result'] = "ERROR";
           $jTableResult['Message'] = $ex->getMessage();
           print json_encode($jTableResult);
      }

I changed version of scripts but only errors change! Can you help me, please?

Thank you very much!

Kay*

misterparsons commented 10 years ago

The list actions should return ['Result'] and ['Records'] PLURAL. create and update return ['Record'] SINGULAR

kay2000 commented 10 years ago

Thank you very much!