Download the PHP package bluetea/ajax-response-bundle without Composer
On this page you can find all versions of the php package bluetea/ajax-response-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bluetea/ajax-response-bundle
More information about bluetea/ajax-response-bundle
Files in bluetea/ajax-response-bundle
Package ajax-response-bundle
Short Description BlueTea AjaxResponse Bundle for Symfony2
License MIT
Informations about the package ajax-response-bundle
AjaxResponse for Symfony2
This repository contains an AjaxResponse implementation which allows you an easy-to-use Ajax implementation in the frontend (javascript) and backend (PHP).
The bundle does relies on the Symfony2 framework and JMS Serializer.
Installation
Get a copy of the repo!
You can load this repository with composer:
If you don't use composer, load the repository with GIT:
Add the bundle to the AppKernel.php:
Implementation
This bundle is implemented automatically in the backend via the AjaxResponseListener. The frontend implementation should be done manually.
Frontend
First we should load the javascript files including jQuery, jQuery-ui, Pnotify and BlockUI.
or with assetic:
Then initialize the ajaxProtocol and blockUi widgets.
Usage
Backend
The AjaxResponse overrides the constructor of the Response object. Two additional parameters are added: type and data. The type is the most important part because it’s used by the ajaxProtocol.js to determine which action is expected. Example: the “modal” type opens a modal. The data parameter is used if you like to send additional data.
There are four types implemented:
- Modal: this type opens a modal
- Redirect: this type triggers a redirect
- Event: this type fires a javascript event which can be catched by other javascript files
- Data: this is the default type and just passed the data
The AjaxResponse contains 5 parameters: content, type, data, status and headers.
The content parameter contains the data of the type:
- Modal type: HTML data for the modal
- Redirect type: the URL
- Event type: the event name
- Data type: the data
So, if you want to send a modal to the frontend your code should look like this:
And if you want to fire an event in javascript:
All possible AjaxResponse types:
Don't pre-serialize the data. The data is serialized to JSON by the AjaxResponseListener.
Frontend
You should use the AjaxProtocol widget to enable all advantages of the AjaxResponse. The AjaxProtocol widget handles modal, redirect and event triggering automatically. If you want to do something manual, override the successCallback and use the DATA type in the AjaxResponse object in the backend.
All options:
Just call an URL. The data parameters contains the POST or GET parameters and the type is default ‘POST’ but can be set to ‘GET’. The beforeSendCallback is a function callback and is executed before the AJAX call is made. The successCallback is a function callback and is executed as the AJAX call is successful. The failCallback is a function callback and is executed as the AJAX call has failed.
Example for a modal:
Example for an event:
Example for posting data:
Example when using dataTables:
All versions of ajax-response-bundle with dependencies
symfony/http-foundation Version 3.4.*
symfony/http-kernel Version 3.4.*