saving of row through jquery jtable throws error

40 views Asked by At

I have four fields in my login table (loginid is the primary key and of type varchar) i have been able to display the records in the jquery jtable. However when i try to create a new record through the modal box of (add new record) using the below code

    else if($_GET["action"] == "create")
    {
        $loginid = $_POST["LoginId"];
        $loginpwd = $_POST["LoginPwd"];
        $logintype = $_POST["LoginType"];
        $loginstatus = $_POST["LoginStatus"];
        $sql = "insert into login(LoginId,LoginPwd,LoginType,LoginStatus) values (?,?,?,?);";
        $params = array($loginid,$loginpwd,$logintype,$loginstatus);
        $stmt = sqlsrv_query($conn,$sql,$params);
        $sql = "select * from login where LoginId='".$_POST["LoginId"]."';";
        $stmt = sqlsrv_query($conn,$sql);
        $rows = array();
        $jTableResult = array();
        while($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC))
        {
            $rows[]=$row;
        }
        $jTableResult['Result'] = "OK";
        $jTableResult['Records'] = $rows;
//      $jTableResult['TotalRecordCount'] = $recordcount;
        print json_encode($jTableResult);
    }

My new records gets inserted in the backend. After the insert, i recieve response due to the ajax call(implying that the create or insertion has been successful), however, the modal dialog box does not close. Also the console shows the following error

error on insertion in jquery jtable Uncaught TypeError: Cannot read property 'LoginId' of undefined     at b.(anonymous function).(anonymous function)._getKeyValueOfRecord (https://visitorpass.yeshasvee.com/JTable/Scripts/jtable/jquery.jtable.js:800:26

The loginid is the primary key in my login table. It is of the type string...Can someone confirm why i am getting this error..

1

There are 1 answers

0
misterP On

Your json response is incorrect.

The createAction expects a SINGLE Record (Not Records) of the new field. ie. $jTableResult['Record'] = $row; You will also need to change your SQL to retrieve the last inserted row.