1 of 2 xajax examples work - El Forum - 11-26-2008
[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-in-10-minutes.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><input type="button" value="test">';
$template['content'] .= '<div id="SomeElementId2"></div><input type="button" value="test2">'; //second test
$this->load->view('testxajax/index', $template);
}
}
Code: <html>
<head>
<title>Xajax 0.5 test</title>
<?=$xajax_js?>
</head>
<body>
<h1><?=$content?></h1>
</body>
</html>
1 of 2 xajax examples work - El Forum - 11-27-2008
[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 ..
1 of 2 xajax examples work - El Forum - 11-27-2008
[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: <?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><input type="button" value="test">';
$template['content'] .= '<div id="SomeElementId2"></div><input type="button" value="test2">'; //second test
$this->load->view('testxajax/index', $template);
}
}
Code: <html>
<head>
<title>Xajax 0.5 test</title>
<?=$xajax_js?>
<?=$javascripts?>
[removed]
function SWEffect(element){
new Effect.SwitchOff(element, {duration:3});
}
[removed]
</head>
<body>
<h1><?=$content?></h1>
<div id="myimage">
<img src="/images/scriptaculous.gif" alt="script.aculo.us" />
<h2>Click me to Switch me off!</h2>
</div>
</body>
</html>
Any ideas on why the third test with scriptaculous doesn't work?
1 of 2 xajax examples work - El Forum - 11-27-2008
[eluser]BrentNJ[/eluser]
nevermind - I tested separately and it works
Code: <html>
<head>
<title>script.aculo.us examples</title>
[removed][removed]
[removed][removed]
</head>
<body>
<div id="ex-switchoff">
test
</div>
</body>
</html>
should work in CI too
|