Controls Ajax from PHP

Installs: 13 304

Dependents: 0

Suggesters: 0

Security: 0

Stars: 15

Watchers: 20

Forks: 5

Open Issues: 7


v1.6.2 2017-09-27 05:35 UTC


Build Status Scrutinizer Code Quality


AjaxCom is a PHP library that allows developers to write their ajax code in PHP with minimal javascript.



  • Append html to elements
  • Prepend html to elements
  • Replace elements with new html
  • Set html of elements
  • Set value of elements
  • Display flash messages
  • Display modals
  • Change URL
  • Call functions


  • PHP >= 5.3.3
  • jQuery >= 1.7.x


Via composer:

    "require": {
        "dm/ajaxcom": "dev-master"



Include the javascript library located at src/DM/AjaxCom/Resources/public/js/ajaxcom.js

Intercept all click events on anchors and submit events on forms:


Or just intercept those which have data-ajaxcom



use DM\AjaxCom\Handler;

if (isset($_SERVER['X-AjaxCom'])) {
    // Render page using AjaxCom library
    $handler = new Handler();
    // Change URL to /newurl
    // Append some html to an element
        ->append('<tr><td>This is a new row</td></tr>');
    // Replace element with some new html
        ->replaceWith('<span id="somethingnew">Some text</span>');
    // Display modal
        '<div class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 id="myModalLabel">Modal header</h3>
            <div class="modal-body">
                <p>One fine body.</p>
            <div class="modal-footer">
                <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
                <button class="btn btn-primary">Save changes</button>
    // NOTE: It is important to call callback() AFTER container() or modal()
    // when you are manipulating the rendered DOM inside the callback;
    // otherwise the callback will be called before elements of DOM are loaded
    // Call funcname()
    // Call namespace.funcname()
    // You can also specify parameters which will be passed as object to the funcion
    $handler->callback('namespace.funcname', ['this' => 'will', 'be' => 'passed', 'as' => 'an object', 'to' => 'the function']);

    header('Content-type: application/json');
    echo json_encode($handler->respond());
} else {
    // Render page normally