• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
1 of 2 xajax examples work

#1
[eluser]BrentNJ[/eluser]
Hi,

Finally got xajax to work.

After the example worked, I tried to add another from

http://www.xajaxproject.org/docs/xajax-i...inutes.php

The test button still works, the new button test2 does not.

Any ideas?

Thanks!!

Code:
<?php
class Testxajax extends Controller
{

    function Testxajax()
    {
      parent::controller();
          $this->load->library('xajax');
          $this->xajax->registerFunction(array('test_function',&$this,'test_function'));
          $this->xajax->registerFunction(array('xajax_myFunction',&$this,'xajax_myFunction')); //  second test
          $this->xajax->processRequest();
    }
  
    function test_function($number)
    {
          $objResponse = new xajaxResponse();
          $objResponse->Assign("SomeElementId","innerHTML", "Xajax is working. Lets add: ".($number+3));
          return $objResponse;
    }  
    
    function xajax_myFunction($arg)   //second test
{
          $newContent = "Value of \$arg: ".$arg;
          $objResponse = new xajaxResponse();
          $objResponse->Assign("SomeElementId2","innerHTML", $newContent);
          return $objResponse;
}

                          
    function index()
    {
        $template['xajax_js'] = $this->xajax->getJavascript(base_url());

        $template['content'] = '<div id="SomeElementId"></div>&lt;input type="button" value="test"&gt;';
        
        $template['content'] .= '<div id="SomeElementId2"></div>&lt;input type="button" value="test2"&gt;'; //second test


        $this->load->view('testxajax/index', $template);
  
    }

}


Code:
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Xajax 0.5 test&lt;/title&gt;
    &lt;?=$xajax_js?&gt;
&lt;/head&gt;

&lt;body&gt;
  <h1>&lt;?=$content?&gt;</h1>
&lt;/body&gt;
&lt;/html&gt;

#2
[eluser]LuckyFella73[/eluser]
hi,

what is missing in your script is the javascrip call.
Add:
Code:
onclick="xajax_test_function(2);"
// and
onclick="xajax_xajax_myFunction('new content');"
to the input/button tags

I wonder how the forst button can work - there is no call
to a function? Maybe it got lost while posting your script here?

btw: "xajax_" is added to your js function names in the sourcecode,
so if you name your xajax fundtion "xajax_myFunction" in your controller
you will find a js function "xajax_xajax_myFunction" in your sourcecode.

Ah - I just noticed that the javascript part I posted into the "forum-code"
tag was removed (wanted to post the complete "input with js code" - maybe
that happened to yours as well ..

#3
[eluser]BrentNJ[/eluser]
When I post the response, the onclick disappears, but they are in the code!

It works now, thanks!! But I have to pass a number, couldn't get the quotes right to pass text.

onclick="xajax_myFunction(4);"

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

    function Testxajax()
    {
      parent::controller();
          $this->load->library('xajax');
          $this->xajax->registerFunction(array('test_function',&$this,'test_function'));
          $this->xajax->registerFunction(array('myFunction',&$this,'myFunction')); //  second test
          $this->xajax->processRequest();
    }
  
    function test_function($number)
    {
          $objResponse = new xajaxResponse();
          $objResponse->Assign("SomeElementId","innerHTML", "Xajax is working. Lets add: ".($number+3));
          return $objResponse;
    }  
    
    function myFunction($arg)   //second test
{
          $newContent = "Value of \$arg: ".$arg;
          $objResponse = new xajaxResponse();
          $objResponse->Assign("SomeElementId2","innerHTML", $newContent);
          return $objResponse;
}

                          
    function index()
    {
        $template['xajax_js'] = $this->xajax->getJavascript(base_url());
        $template['javascripts'] = $this->xajax->getJavascript(base_url());

        $template['content'] = '<div id="SomeElementId"></div>&lt;input type="button" value="test"&gt;';
        
        $template['content'] .= '<div id="SomeElementId2"></div>&lt;input type="button" value="test2"&gt;'; //second test

        $this->load->view('testxajax/index', $template);
  
    }

}


Code:
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Xajax 0.5 test&lt;/title&gt;
    &lt;?=$xajax_js?&gt;
    &lt;?=$javascripts?&gt;
    
    [removed]
    function SWEffect(element){
       new Effect.SwitchOff(element, {duration:3});
    }
    [removed]

&lt;/head&gt;

&lt;body&gt;
  <h1>&lt;?=$content?&gt;</h1>
  
  <div id="myimage">
    <img src="/images/scriptaculous.gif" alt="script.aculo.us" />
    <h2>Click me to Switch me off!</h2>
  </div>
    
&lt;/body&gt;
&lt;/html&gt;


Any ideas on why the third test with scriptaculous doesn't work?

#4
[eluser]BrentNJ[/eluser]
nevermind - I tested separately and it works

Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;script.aculo.us examples&lt;/title&gt;

   [removed][removed]
   [removed][removed]

&lt;/head&gt;
&lt;body&gt;



<div id="ex-switchoff">
test
</div>



&lt;/body&gt;
&lt;/html&gt;


should work in CI too


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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