0

I want to use jquery to get courses from the database when i click the level dropdown control.

The Jquery code in my view

   <script type="text/javascript">
    function getcourses()
    {
    var clevel = $('#clevel').val();
    var did = $('#did').val();
    var tday = $('#tday').val();
    var csrf_value = $('input[csrf_test_name]').val();
    var postdata = {
        'clevel': clevel,
        'did': did,
        'day': tday,
        'csrf_value': csrf_value
    };

    $.ajax({
        type: 'POST',
        url: 'http://localhost:8056/timetable/Admin/GetTbCourse/',
        data: postdata,
        datatype: 'json',
        success: function(result){
            $("#tm4_5").val(result.tbcourses['t0405']);

        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert("Status " + jqXHR.status);
        }
    });
}

The controller code

public function GetTbCourse() {

    $day = $this->input->post('day');
    $dept = $this->input->post('did');
    $clevel = $this->input->post('clevel');

    $getcourse = $this->MTimetable->ListTime($day, $dept, $clevel);


    $this->data['tbcourses'] = $getcourse;
     json_encode($this->data);

    }
</script>

please how do i get the result sent by my controller to put in the text field one of which is

<input type="text" class="form-control" id="tm2_3" name="tm2_3" />

Thanks

0 Answers0