jquery – How to access json decoded object in php-ThrowExceptions

Exception or error:

I have output checkbox fields from a database query. When the user clicks a box I want the selection value entered as a hash parameter in the url. I want to also use this parameter in an ajax call to get a parameter that I can then enter in another load_data ajax call which filters a dynamic table of data.

I have most of this working but the jQuery marked function will only accept row id as a parameter and not any other row names. Also the alert (which I have only put in for testing purposes) shows int(10) but I only want it to show 10.

Putting the onchange in the function wasn’t working so I have put it on the individual input fields.

This is part of the mysqli query

echo '<input class="category-clear-selection authors"  type="checkbox" value=" '.$row["lastname"].' " id=" '.$row["lastname"].' "   onchange="marked(' . $row['id'] . ')"       >' 

This is the function

function marked(param1) {
  location.hash = (param1);
  var filter = [];

  $(param1).each(function() {
    filter.push($(this));
    var filterStr = JSON.stringify(filter);

    $.ajax({
      url: 'filters-file.php',
      type: 'post',
      data: {
        filter: filterStr
      },
      success: function(response) {
        alert(response);
        var query = (response); //use the response as a query and send the query to the load_data function to search the books dynamic table
        load_data(1, query);
      }
    });
  });
}

This is the code for the function response

<?php //this file is used for handling the php to jquery function on click
  //Retrieve the string, which was sent via the POST parameter 
  $filter = $_POST['filter'];

  //Decode the JSON string and convert it into a PHP associative array.
  $decoded = json_decode($filter, true);

  //var_dump the array so that we can view it's structure.
  // var_dump($decoded);
  // echo ($decoded);
  console.log($decoded);

  foreach ($decoded as $k=>$v)
  {
    var_dump($v[0]); // etc.
  }
?>
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *