Welcome Guest, Not a member yet? Register   Sign In
Using a database model function with an ajax?
#1

[eluser]Jordz[/eluser]
Morning (Well it is here anyway :p),

For the past hour I've been experimenting with AJAX, it's not fully implemented into my CI app just yet I just load a view from my controller. My question is how would I send the ajax function to a database model in my CI app?
Code:
[removed][removed]
    [removed]

        $(document).ready(function(){
            $('#txtValue').keyup(function(){
                sendValue($(this).val());  
              
            });
          
        });
        function sendValue(str){
            $.post("http://localhost:8888/ajax.php",{ sendValue: str }, //<- Here... I've tried  tried putting my PHP AJAX
//controller in here as /test/ajax and even like $this->test_model->ajax()
            
function(data){
                $('#display').html(data.returnValue);
            }, "json");
          
        }

How would I go about putting the php that controls the ajax into my CI framework without creating other files that are going to clog things up.


Thanks

Jordan.
#2

[eluser]n0xie[/eluser]
Just build an Ajax controller and code it like you would any other controller. The only difference would be instead of returning a view, you return a json_encod'ed array.
#3

[eluser]Jordz[/eluser]
Ahhh sorry about that, what I did was just that, the only stupid thing I did was forget that I don't have mod_rewrite on therefore I need my index.php in my url! Tongue

My bad, really sorry.

Jordan




Theme © iAndrew 2016 - Forum software by © MyBB