Author Topic: Can not get data to be saved in MySQL  (Read 3687 times)

iznogood1

  • Newbie
  • *
  • Posts: 2
    • View Profile
Can not get data to be saved in MySQL
« on: June 21, 2016, 09:20:06 pm »
Hi,

I can get data from a MySQL table, but I can not get it after having edited somme cells to send it back in the MySql table.

The grid is dispalyed in a div: <div id="grid_php"></div>
And a "button" should allow to save the grid : <div id="button1">Bouton1</div>

Here is the code.
Unfortunately, in the $("div#button1").click(function(), "alert (data1)" displays "undefined".
Then nothing is sent to my test.php code that sould save the data.

Can somebody explain me what is wrong ?

$(function () {
        var colM = [
            { title: "Id", width: 100, dataIndx: "id" , editable: false, sortable: false },           
            { title: "Order ID", width: 130, dataIndx: "order_id" , editable: true, sortable: true, validations: [ { type: 'gt', value: '10', msg: 'Required' } ] },
            { title: "Invoice Date", width: 190, dataIndx: "invoice_date" , editable: true}
        ];
      
        var dataModel = {
            location: "remote",                       
            dataType: "JSON",
            method: "GET",
            getUrl : function () {               
                return { url: 'remote.php'};
            },
            getData: function ( response ) {               
                return { data: response };               
            },
         //postData: {colModel: colM, dataModel: dataModel}
        };
            
        $("div#grid_php").pqGrid({ width: 900, height: 400,
         collapsible: true,
            dataModel: dataModel,
            colModel: colM       
        });
      
      $("div#button1").click(function(){
            var data1 = JSON.stringify(dataModel.data);
            alert (data1);
             $.ajax({
               url : 'test.php',
               type : 'GET',
               dataType : 'html',
               data : data1,
               success : function(code_html, statut){
                  alert(code_html);
               },
               error : function(resultat, statut, erreur){
                  alert('error');
               }
            });
      });
    });

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6265
    • View Profile
Re: Can not get data to be saved in MySQL
« Reply #1 on: June 22, 2016, 12:20:41 pm »
To access the data in grid, instead of dataModel.data

try this $("#grid_php").pqGrid( "option", "dataModel.data" );

iznogood1

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Can not get data to be saved in MySQL
« Reply #2 on: June 22, 2016, 01:57:49 pm »
That is working.

Thanks a lot.