Welcome Guest, Not a member yet? Register   Sign In
Problem with AJAX and library functions
#1

[eluser]Unknown[/eluser]
Suppose I load a library in the controller's constructor, then I register a controller function with Xajax. When the Xajax function is called, it will use a function from the library.

Code:
Class TestController Extends Controller {
    
    var $MyLibrary;
    
    function __construct()
    {
        parent::Controller();
        
        // Load Xajax stuff
        
        $this->load->library('xajax');
        $this->xajax->registerFunction(array('_xajaxTest', $this, '_xajaxTest'));
        $this->xajax->processRequest();
        
        $data['xajax_js'] = $this->xajax->getJavascript($_SERVER['REQUEST_URI']);
        
        // Load library

        $this->load->library('My_Library');
    }

    function _xajaxTest()
    {  
        $this->MyLibrary = new My_Library();
        $output = MyLibrary->randomNumber();
    
        // Set the response text
        
        $objResponse = new xajaxResponse();
        $objResponse->Assign("number", "innerHTML", $output);
        return $objResponse;
    }
}

When the function is called, however, the output is never shown. Firebug shows that the POST response was returned, but it doesn't show up on the page. Instead I get a 'waiting' cursor in the browser. If I assign $output directly without using the library condtructor or function, it works correctly.

Xajax seems to not do well with calling functions from libraries loaded in the controller it resides in. How can I use functions from libraries within registered Xajax functions?




Theme © iAndrew 2016 - Forum software by © MyBB