Example #1
0
 public function testContainer()
 {
     $ajax = new Handler();
     $container = $ajax->container('#123')->html('<b>test</b>');
     $response = $ajax->respond();
     $expected = '{"ajaxcom":[{"operation":"container","options":{"target":"#123","animate":true,"value":"<b>test<\\/b>","method":"html"}}]}';
     $this->assertEquals($response, $expected);
 }
Example #2
0
<?php

require_once '../vendor/autoload.php';
use DM\AjaxCom\Handler;
$query = '';
if (!empty($_GET['q'])) {
    $query = strtolower($_GET['q']);
}
if (!empty($_GET['id'])) {
    $id = $_GET['id'];
}
$handler = new Handler();
/**
 * Normally, you would get the new row from partial
 */
$newRowId = rand(4, 100);
$newRow = " <tr id='row{$newRowId}'>\n                <td>{$newRowId}</td>\n                <td>" . (!empty($_POST['firstname']) ? $_POST['firstname'] : 'Test') . "</td>\n                <td>" . (!empty($_POST['lastname']) ? $_POST['lastname'] : 'Row') . "</td>\n                <td>" . (!empty($_POST['username']) ? $_POST['username'] : '******') . "</td>\n                <td>\n                   <a href='/example/backend.php?q=edit&id=row{$newRowId}' class='btn' data-ajaxcom>Edit</a>\n                   <a href='/example/backend.php?q=delete-by-id&id=row{$newRowId}' class='btn btn-danger' data-ajaxcom>Delete</a>\n                </td>\n            </tr>\n            ";
switch ($query) {
    case "edit":
        $handler->modal();
        break;
    case "append":
        $handler->container('#example-table tbody')->append($newRow);
        break;
    case "delete-by-id":
        $handler->container('#' . $id)->remove();
        break;
    case "change-url":
        $handler->changeUrl('/example/new-url');
        break;
    case "delete-by-class":