0

I have this problem with assigning a certain array variable. When I post it to Codeigniter Controller, It produces this error Click to view Image.

View:

<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script>    

 function submit() {
        var TableData = {"table1":"sample1","table2":"sample2","table3":"sample3"};
        var Data = JSON.stringify(myTableArray);
        $.ajax({
          type: "POST",
          url: "http://janncomputing/tabulation/judges/save_Production",
          data: {pTableData : Data},
          success: function(result){ //retrieve data
            alert('Success');
            alert(result); //alert it
          }//success
        });
    </script>
  </head>
  <body>
    <div>
      <button type="button" onClick="submit();">SUBMIT</button>
    </div>
  </body>
</html>

Controller:

public function save_Production()
{

    $table = json_decode($_POST['pTableData'],true);
    $msg = $table['table1'];  
    echo $msg;  

}
Marylyn Lajato
  • 1,171
  • 1
  • 10
  • 15
WCJ
  • 3
  • 5

1 Answers1

0

try this

function submit()
{
    var TableData = {"table1":"sample1","table2":"sample2","table3":"sample3"};
    //var Data = JSON.stringify(TableData);
    $.ajax({
        type: "POST",
        url: "http://janncomputing/tabulation/judges/save_Production",
        dataType: 'json',
        data: {pTableData : TableData},
        success: function(result){ //retrieve data
            alert('Success');
            alert(result); //alert it
        }//success
    });
}
Atural
  • 5,389
  • 5
  • 18
  • 35