0

I'm using a MVC framework and in my view I have my javascript code

this is in my view:

<script>
$(document).ready(function(){
    $(document).on('click','#filtr',function(){
        var id_val = $('#id_val').val();
        var key_val= $('#key_val').val();
        console.log(id_val);
        console.log(key_val);
        $.ajax({
            url:"<?php echo base_url()?>filter/filtr",
            method:"POST",
            data:{
                id_val:id_val,
                key_val:key_val
            },
            /*beforeSend:function(){
                $("container_tab").html("Searching...");
            },*/
            success:function(data){
                $("container_tab").html(data);
            }
        })
    });
});
</script> 
<div class="table-responsive">
<table class="table table-striped table-hover" id="dataTables-example">
<tr>
    <td>
        Filter by...
    </td>
    <td>
        ID: <input type="text" id="id_val" name="id_val" value="3" />
    </td>
    <td>
        KEY: <input type="text" id="key_val" name="key_val" value="asdf12" />
    </td>
    <td>
        <button type="button" class="btn btn-info btn-sm" id="filtr">FILTER</button>
    </td>
</tr>

<br />
<div id="container_tab"></div>
</table>
</div>

I want the table that comes back from my controller to fill <div id="container_tab"></div>

in my filter controller I have my filtr function, but this function for now does not return $filter_list even though I'm still not doing the actual query.

public function filtr(){
    $filter_list = '';
    $filter_list .= '
                    <tr>
                            <td style="vertical-align: middle;" class="text-center">this should be sent to view as a table row</td>
                    </tr>
            ';

    echo $filter_list;

}

when I do a console.log within my javascript function the values '3' and 'asdf12' are display but I'm not getting anything back on screen from my controller function calling filtr.

6
  • 1
    Where are your table tags? Also any PHP errors? Commented Sep 25, 2016 at 16:02
  • Where is container_tab that you are trying to fill with the results? Commented Sep 25, 2016 at 16:08
  • my table tag is at the botom of my view. Commented Sep 25, 2016 at 16:17
  • @RiggsFolly the container_tab is at the end of my view as <div id="container_tab"></div> and @mplungjan there are no php errors thrown and the table tags have been added all i did was copy and paste so i didn't copy those now they are there. Commented Sep 25, 2016 at 17:02
  • 1
    Then change $("container_tab").html(data); to $("#container_tab").html(data); Commented Sep 25, 2016 at 17:02

1 Answer 1

1

There is a minor error in your success function, your containor has a id called container_tab so use a # in front of its name like this

success:function(data){
    $("#container_tab").html(data);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.