Welcome Guest, Not a member yet? Register   Sign In
Need help understanding CI and AJAX
#1

[eluser]philfry[/eluser]
I have a table that is loaded on page load and it basically has some logic in the model that does a db query and then shows the results in a table. I have put a text box and a button at the top of the table and I want to be able to search and update the results on the page. I have tried adding some jquery that would look for a button click but i'm just not understanding what I need to do for this to happen.

this is my javascript but i'm sure i'm missing a big piece about what needs to happen. Any direction would be really helpful.

$(function(){
$("#searchBtn").click(function(){

$.ajax({
type: "post",
url: "tablelist/searchquery/" + $('searchquery').val()

});

});
});
#2

[eluser]Matias Perrone[/eluser]
While the code is fine you need to check out the jquery documentation, basically you need to set up the "success" function.
#3

[eluser]noideawhattotypehere[/eluser]
Using $.post and $.get seems a lot of easier for me. Is it a bad habit? Dunno. But here is a simple example:
Code:
//get
$( document ).ready(function () {
$("#btnid").click(function () {    
$.get("'.base_url().'controller/method/"+param, function (return) {
                            $("#divnameuwantreturneddata").html(return);
                        });
  });
});

//post example
$.post("'.base_url().'controller/method/"+param, { "postname":yourvariable });  
you can access it then using like always $this->input->post('postname')
#4

[eluser]philfry[/eluser]
I ended up just using a jquery plugin called quicksearch to filter the table. Thanks a lot for that example that is useful.




Theme © iAndrew 2016 - Forum software by © MyBB