Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/everlutionsk/ajaxcom
AjaxCom - control front-end from PHP
https://github.com/everlutionsk/ajaxcom
Last synced: about 1 month ago
JSON representation
AjaxCom - control front-end from PHP
- Host: GitHub
- URL: https://github.com/everlutionsk/ajaxcom
- Owner: everlutionsk
- License: mit
- Created: 2012-11-26T22:15:47.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2017-09-27T05:35:58.000Z (over 7 years ago)
- Last Synced: 2024-11-22T16:47:10.675Z (about 2 months ago)
- Language: JavaScript
- Homepage: http://ajaxcom.everlution.sk/
- Size: 200 KB
- Stars: 15
- Watchers: 20
- Forks: 5
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://scrutinizer-ci.com/g/everlutionsk/AjaxCom/badges/build.png?b=master)](https://scrutinizer-ci.com/g/everlutionsk/AjaxCom/build-status/master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/everlutionsk/AjaxCom/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/everlutionsk/AjaxCom/?branch=master)# AjaxCom
AjaxCom is a PHP library that allows developers to write their ajax code in PHP with minimal javascript.### Demo
http://ajaxcom.everlution.sk/## Features
- 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## Requirements
- PHP >= 5.3.3
- jQuery >= 1.7.x## Installation
Via composer:``` json
{
"require": {
"dm/ajaxcom": "dev-master"
}
}
```## Usage
### Javascript
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:
``` javascript
$(document).ajaxcom();
```Or just intercept those which have `data-ajaxcom`
``` javascript
$(document).ajaxcom('[data-ajaxcom]');
```### PHP
``` php
use DM\AjaxCom\Handler;if (isset($_SERVER['X-AjaxCom'])) {
'
// Render page using AjaxCom library
$handler = new Handler();
// Change URL to /newurl
$handler->changeUrl('/newurl');
// Append some html to an element
$handler->container('#table')
->append('This is a new row');
// Replace element with some new html
$handler->container('#something')
->replaceWith('Some text');
// Display modal
$handler->modal(
'
);
// 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()
$handler->callback('funcname');
// Call namespace.funcname()
$handler->callback('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
}
```