Welcome Guest, Not a member yet? Register   Sign In
ajax implementation
#1

[eluser]Unknown[/eluser]
Can anyone send me simple ajax application in codeigniter.I know how to implement ajax in PHP.I am beginer with this tool,please send me small ajax example in codeigniter.
#2

[eluser]n0xie[/eluser]
Code:
class Ajaxexample extends Controller {

    function Ajaxexample()
    {
        parent::Controller();    
       }
    
    function myawesomeajaxfunction()
    {
        // Load model
        $this->load->model('somemodel');
        
        // Get some data
        $data = $this->somemodel->somemethod();
        
        // return data to the browser either via a view, or since it's an ajax call,
                // in the example we just echo it directly from the controller        
        echo json_encode($data);
    }

Call '/ajaxexample/myawesomeajaxfunction' from your view/html.
Mind you there is no validation or sanitation, but you get the idea.
#3

[eluser]Crimp[/eluser]
You may want to check that the call is indeed a XHR call to the method.




Theme © iAndrew 2016 - Forum software by © MyBB