Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] AJAX jquery getting data from php function
#1

[eluser]SPeed_FANat1c[/eluser]
Hi, probably this is simple, but I can't find how to do it, I think this will be faster if I post it here.

So there is my view file:

Code:
<sc+ript src="/plotai/js/jquery-1.3.2.min.js" ></sc+ript>
    
    
    <sc+ript languge="javascript" type="text/javascript">

    $(function(){
        $('.test').live('click',function(){

            
            $.ajax({
                type: "POST",
                url: "/plotai/test/test_controller/retrieve",        //this function returns some data
                
                success: function(){
                    var data = 'asd';        //I want data to be assigned to this variable
                    alert(data);
                }//success
                
            });    
        return false;
        });    //click
    });

    </sc+ript>
    

    <a class = "test" href="url">Link text</a>

And there is controller:

Code:
&lt;?php
class Test_controller extends Controller {

    function Test_controller(){
        parent::Controller();
        
      

    }
    function index()
    {

           $this->load->view('test/page');
    }
    
  
    
    
    
    function retrieve()
    {
        return 'filter';
    }
        
}            
            
?&gt;

So, how can I get the data for $('.test').live('click',function() ? Actually in real project the retrieve function updates database and redirects to other function depending on what the filter is. But I want use AJAX, so redirecting misfits here. Javasrictp must get the filter and depending on it load the appropriate function in the controller.
#2

[eluser]danmontgomery[/eluser]
Code:
success: function(data){
                    alert(data);
                }//success
#3

[eluser]SPeed_FANat1c[/eluser]
thanks




Theme © iAndrew 2016 - Forum software by © MyBB