Closed frecervantes closed 7 months ago
Hi,
Starting from v4, the global functions are namespaced.
use Jaxon\jaxon;
$jaxon = jaxon();
You register classes and not objects.
$jaxon->register(\Jaxon\Jaxon::CALLABLE_CLASS, HelloWorld::class);
The changes are documented here: https://www.jaxon-php.org/docs/v4x/about/changes.html.
Mr Feuzeu, excuse my limited knowlege on js, but i'm just trying to build a functional script in order to leave xajax behind. at least using functions at the begining, but i still getting an error. may you help please?
<?php require_once 'vendor/autoload.php';
use Jaxon\Jaxon; use function Jaxon\jaxon;
function hello_world($isCaps){ $response = jaxon()->newResponse(); $text = ($isCaps) ? 'HELLO WORLD!' : 'Hello World!'; $response ->assign('div2', 'innerHTML', $text); return $response; } $jaxon = jaxon(); $jaxon->register(Jaxon::CALLABLE_FUNCTION, "hello_world");
?>
<!DOCTYPE html>
error: jaxon_hello_world is not defined ??
thanks for your help regards
This is a complete example of using Jaxon like Xajax. I usually do not recommend (because of the mix of html, js and php code) but since you are just migrating from Xajax.
<?php
require('./vendor/autoload.php');
use Jaxon\Jaxon;
use function Jaxon\jaxon;
function hello_world($isCaps)
{
$response = jaxon()->newResponse();
$text = ($isCaps) ? 'HELLO WORLD!' : 'Hello World!';
$response->assign('div1', 'innerHTML', $text);
return $response;
}
$jaxon = jaxon();
$jaxon->register(Jaxon::CALLABLE_FUNCTION, "hello_world");
// Process the request.
if($jaxon->canProcessRequest())
{
$jaxon->processRequest();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Jaxon Examples</title>
</head>
<body>
<div id="div1"> </div>
<input type="button" value="Say Hello" onclick="jaxon_hello_world(true)" />
</body>
<!-- Jaxon CSS -->
<?php
echo $jaxon->getCss(), "\n";
?>
<!-- Jaxon JS -->
<?php
echo $jaxon->getJs(), "\n";
?>
<!-- Jaxon script -->
<?php
echo $jaxon->getScript(), "\n";
?>
</html>
You can replace jaxon_hello_world(true)
with jaxon_hello_world(false)
to see the change.
Make sure you have this in the source code of your page.
jaxon_hello_world = function() {
return jaxon.request({ jxnfun: 'hello_world' }, { parameters: arguments });
};
thank you very, very much Mr. Frezeu, this is what I needed to start using the Jaxon library, fully functional, as I become more familiar with it, I am sure I will be able to use it in the best way and explore its full potential and I will certainly ask for your appreciated help.
Regards
You're welcome!
I've added this example to the online docs: https://www.jaxon-php.org/docs/v4x/about/example.html I also fixed the examples, and added a warning message since they work with the version 2.x of the library. https://www.jaxon-php.org/examples.html
We appreciate your help and effort in maintaining the jaxon library and any example to show the use of the different features, no matter how simple, is a great help in implementing and understanding how jaxon works. Thus, I encourage you to show, through examples, the functionalities of this great software.
again thank you very much.
Hi, i'm using your code, intalled on win 10 using composer, wamp, php.7.4, just trying to see this working, migrating from xajax, but a bit confuse... this is the script.
<?php // Incluye el archivo Jaxon require_once 'vendor/autoload.php'; use Jaxon\Jaxon; use function Jaxon\jaxon;
// $jaxon = jaxon();
function hello_world($isCaps){ $response = jaxon()->newResponse(); $text = ($isCaps) ? 'HELLO WORLD!' : 'Hello World!'; $response->assign('div2', 'innerHTML', $text); return $response; }
$jaxon = jaxon(); $jaxon->register(Jaxon::CALLABLE_FUNCTION, "hello_world");
?>
<!DOCTYPE html>
Aplicación Hola Mundo con Jaxon
error: jaxon_hello_world is not defined ??
thank for your help
regards