PHP Classes

Jaxon: Call PHP classes from JavaScript using AJAX

Recommend this page to a friend!
  Info   Example   Demos   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStarStar 80%Total: 598 All time: 5,209 This week: 49Up
Version License PHP version Categories
jaxon-core 3.1.7BSD License5PHP 5, Language, AJAX, Traits
Description 

Authors

Jared White
J. Max Wilson
Joseph Woolley
Steffen Konerow
Thierry Feuzeu


Contributor

This package can call PHP classes from JavaScript using AJAX.

It can register objects of classes or global functions and process AJAX requests that are handled by the registered functions.

The package can register directories of classes, so it is not necessary to register each class in each directory at once, with support to namespaces.

The classes are autoloaded on demand, so only the classes that necessary for each AJAX request will be loaded.

The AJAX calls are done by a separate JavaScript library which can eventually be retrieved from a CDN (Content Delivery Networt) so it does not have to be installed by this package.

Innovation Award
PHP Programming Innovation award nominee
July 2016
Number 2


Prize: One downloadable copy of Komodo IDE
Many Web applications have browser side (JavaScript) code making AJAX calls to server side code in PHP that is mapped to classes of objects.

Usually the server side code needs to register classes or functions that will handle the AJAX calls.

However, when you have many classes to handle your Web application AJAX calls, registering classes one by one can be a tedious time consuming task.

The package provides a more efficient method to register many classes at once. You just specify a directory and the package will lookup and load the classes on demand when the AJAX calls are received.

This way you also do not have to waste time instantiating objects of the handler classes until they are necessary.

Manuel Lemos
Picture of Thierry Feuzeu
  Performance   Level  
Innovation award
Innovation award
Nominee: 1x

 

Recommendations

Recommendation for a PHP class to how to call class and function
Call functions and class in PHP and HTML page

Example

<?php

require (__DIR__ . '/vendor/autoload.php');

use
Jaxon\Jaxon;
use
Jaxon\Response\Response;
use
Jaxon\Request\Factory as xr;

class
HelloWorld
{
    public function
sayHello($isCaps)
    {
        if (
$isCaps)
           
$text = 'HELLO WORLD!';
        else
           
$text = 'Hello World!';

       
$xResponse = new Response();
       
$xResponse->assign('div2', 'innerHTML', $text);

        return
$xResponse;
    }

    public function
setColor($sColor)
    {
       
$xResponse = new Response();
       
$xResponse->assign('div2', 'style.color', $sColor);
       
        return
$xResponse;
    }
}

// Register object
$jaxon = jaxon();

$jaxon->readConfigFile(__DIR__ . '/config/class.php', 'lib');

$jaxon->register(Jaxon::CALLABLE_OBJECT, new HelloWorld());

// Process the request, if any.
$jaxon->processRequest();

?>
<script type='text/javascript'>
    /* <![CDATA[ */
    window.onload = function() {
        // Call the HelloWorld class to populate the 2nd div
        <?php echo xr::call('HelloWorld.sayHello', 0) ?>;
        // call the HelloWorld->setColor() method on load
        <?php echo xr::call('HelloWorld.setColor', xr::select('colorselect')) ?>;
    }
    /* ]]> */
</script>
                        <div class="col-md-12" id="div2">
                            &nbsp;
                        </div>
                        <div class="col-md-4 margin-vert-10">
                            <select class="form-control" id="colorselect" name="colorselect"
                                    onchange="<?php echo xr::call('HelloWorld.setColor', xr::select('colorselect')) ?>; return false;">
                                <option value="black" selected="selected">Black</option>
                                <option value="red">Red</option>
                                <option value="green">Green</option>
                                <option value="blue">Blue</option>
                            </select>
                        </div>
                        <div class="col-md-8 margin-vert-10">
                            <button type="button" class="btn btn-primary" onclick="<?php echo xr::call('HelloWorld.sayHello', 0) ?>; return false;" >Click Me</button>
                            <button type="button" class="btn btn-primary" onclick="<?php echo xr::call('HelloWorld.sayHello', 1) ?>; return false;" >CLICK ME</button>
                        </div>


Details

Build Status Scrutinizer Code Quality StyleCI

Latest Stable Version Total Downloads Latest Unstable Version License

The Jaxon core library

Jaxon is an open source PHP library for easily creating Ajax web applications. It allows into a web page to make direct Ajax calls to PHP classes that will in turn update its content, without reloading the entire page.

Jaxon is a fork of the Xajax PHP library.

This package is the Jaxon core library. Several plugins are provided in separate packages.

Features

  • All the Jaxon classes in a directory can be registered in one shot, possibly with a namespace.
  • The configuration settings can be loaded from a file. Supported formats are JSON, YAML and PHP.
  • The library provides pagination feature out of the box.
  • The library is modular, and consists of a core package and several plugin packages.
  • The javascript library is provided in a separated and javascript-only package, loaded by default from the jsDelivr CDN.
  • The generated javascript classes are named according to their namespace or the subdirectory where they are located.
  • All PHP packages install with `Composer`, are fully namespaced, and implement `PSR-4` autoloading.
  • The library natively implements Ajax file upload.
  • The library runs on PHP versions 5.4 to 7.X.

Documentation

The project documentation is available in English and French.

Some sample codes (only for version 2.x) are provided in the jaxon-php/jaxon-examples package, and demonstrated in the website.

Contribute

  • Issue Tracker: github.com/jaxon-php/jaxon-core/issues
  • Source Code: github.com/jaxon-php/jaxon-core

License

The project is licensed under the BSD license.


  Hello World ClassExternal page   Hello World FunctionExternal page  

Open in a separate window

Open in a separate window

  Files folder image Files (130)  
File Role Description
Files folder imagesrc (3 files, 8 directories)
Files folder imagetemplates (3 directories)
Files folder imagetests (2 directories)
Files folder imagetranslations (3 directories)
Accessible without login Plain text file .styleci.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file class.php Example Example of Jaxon class
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file hello.php Example Example of Jaxon function
Accessible without login Plain text file HOWTO.md Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Readme

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Reuses Unique User Downloads Download Rankings  
 96%3
Total:598
This week:0
All time:5,209
This week:49Up
 User Ratings  
 
 All time
Utility:100%StarStarStarStarStarStar
Consistency:100%StarStarStarStarStarStar
Documentation:100%StarStarStarStarStarStar
Examples:100%StarStarStarStarStarStar
Tests:-
Videos:-
Overall:80%StarStarStarStarStar
Rank:16