using ajax

#11
[eluser]Jagar[/eluser]
That is wrong, I don't know if you can have a function inside a function, but change it to following and it should work:

Code:
function index() {
  $this->load->library('xajax/xajax');    
  //$this->xajax->registerFunction("test_function"); does not work in class this way
    $this->xajax->registerFunction(array($this,"test_function"));
  $this->xajax->processRequest();
  $template['xajax_js'] = $this->xajax->getjavascript('../../');
  $template['content'] = '<div id="SomeElementId"></div>&lt;input type="button" value="test"&gt;';
  $this->load->view('template', $template);
}


  function test_function($number) {
    $objResponse = new xajaxResponse();
    $objResponse->assign("hello","value", "Xajax is working. Lets add: ".($number+3));
    return $objResponse;
  }

#12
[eluser]sl3dg3hamm3r[/eluser]
thx!
but doesn't help either, still same error...

#13
[eluser]Jagar[/eluser]
This is how mine is:

[system]
[application]
[libraries]
[xajax]
[plugin_layer]
legacy.php
xajax.php
...
...


Code:
class Test extends Controller {
    function Test(){
        parent::Controller();
    }
    
    function index(){
        $this->load->library('xajax/xajax');
        $this->xajax->registerFunction(array($this,"test_xajax"));
        $data['xajax_script'] = $this->xajax->getJavascript("/scripts");
        $this->xajax->processRequest();
        $this->load->view("view_name",$data);        
    }
    
    function test_xajax(){
        $objR = new xajaxResponse();
        $objR->assign('feedback','innerHTML','Hello from xajax');
        return $objR;
    }
}

Please let me know if that works, the only reason you are getting that redeclared is because you may have it defined somewhere else, make sure you haven't done any includes anywhere in your controller. The only way you will get it to load is through $this->load->library('xajax/xajax');

#14
[eluser]sl3dg3hamm3r[/eluser]
Thank you for your help!
I will try more during next week, if it won't work, I will install a fresh CI-setup and try again. I will post here my results.
Did you also rename xajax.inc.php into xajax.php?

#15
[eluser]Jagar[/eluser]
Yes, I renamed from xajax.inc.php to xajax.php

#16
[eluser]sl3dg3hamm3r[/eluser]
Uh... I hardly dare to tell: I named my controller 'xajax', that's why! Sad ... well, at least I can now finally start and learn with it Wink

thx for your support!

#17
[eluser]Jagar[/eluser]
no wonder it was throwing you that error, glad you got it working!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.