-3

I am using HMVC with CodeIgniter 3 and I need to list some datas in a certain select, based on other select.

So far I have this method in my Modelos controller, that is intended to be used to populate the second select:

public function select_by_id_marca()
{
    $data = array();

    $this->db->order_by($this->primary_key, 'DESC');
    $this->db->get_where('marca', array('id' => $this->input->post('hdn_id_marca')));
    $query = $this->db->get($this->table);

    foreach ($query->result_array() as $row) {
        $data[] = $row;
    }

    $query->free_result();

    return $data;
}

And this is the Ajax:

$('#id_marca').change(function() {
    var selectedId = $(this).find('option:selected').val();
    $('#hdn_id_marca').attr('value', selectedId);

    $.ajax({
        url: '/admin/modelos/select_by_id_marca',
        data: selectedId,
        type: 'POST',
        success: function() {

        }
    });
});

I am actually facing too a 500 Internal Server Error when changing the first #id_marca, but I also need a solution to make this work. Thank you.

gamofe
  • 3,008
  • 4
  • 38
  • 76
  • A 500 error means that somewhere on your server is an error (in an error log) that will tell you exactly why this failed. Find your error and post it here and we can assist. – Mikel Bitson Dec 07 '15 at 15:39
  • @MikelBitson Where can I find it from Firefox? – gamofe Dec 07 '15 at 15:48
  • If you get a 500 error it means that there is an error on your server side, not your browser side. You wont find the error message using the browser- you have to get the error from the php error log on the server. Google that and you'll find SO threads like this http://stackoverflow.com/questions/3531703/how-to-log-errors-and-warnings-into-a-file and http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php – Mikel Bitson Dec 07 '15 at 15:51

1 Answers1

0

You pass just a simple value via your ajax call:

    data: selectedId,
                ^---value only, no key

Then try to access a non-existent key in your PHP code:

$this->db->get_where('marca', array('id' => $this->input->post('hdn_id_marca')));
                                                                 ^^^^^^

Perhaps you want

 data: {"hdn_id_marca":selectedId}

instead.

Marc B
  • 340,537
  • 37
  • 382
  • 468
  • I am facing a 500 Internal Error. I do not know why, I set the route for this controller but still, nothing. – gamofe Dec 07 '15 at 16:14
  • then look at the server log for details about the 500. that takes a few seconds to do, v.s. staring at the code trying to GUESS what the problem might be. – Marc B Dec 07 '15 at 16:15
  • I am not managing to find it or to write new log files in Linux. – gamofe Dec 07 '15 at 16:27