Controls Ajax from PHP

Installs: 2 274

Dependents: 0

Stars: 12

Watchers: 14

Forks: 9

Open Issues: 7

Language: PHP

1.4.2 2015-09-17 10:23 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
    // Call funcname()
    // 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>

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