PHPackages                             bluetea/ajax-response-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. bluetea/ajax-response-bundle

AbandonedArchivedSymfony-bundle[HTTP &amp; Networking](/categories/http)

bluetea/ajax-response-bundle
============================

BlueTea AjaxResponse Bundle for Symfony2

v1.3.0(6y ago)110.1k5MITJavaScript

Since Dec 11Pushed 6y ago7 watchersCompare

[ Source](https://github.com/BlueTeaNL/AjaxResponseBundle)[ Packagist](https://packagist.org/packages/bluetea/ajax-response-bundle)[ RSS](/packages/bluetea-ajax-response-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (12)Used By (0)

AjaxResponse for Symfony2
=========================

[](#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
============

[](#installation)

Get a copy of the repo!
-----------------------

[](#get-a-copy-of-the-repo)

You can load this repository with composer:

```
composer.phar require "bluetea/ajax-response-bundle" dev-master
```

If you don't use composer, load the repository with GIT:

```
git clone https://github.com/BlueTeaNL/AjaxResponseBundle.git your-directory
```

Add the bundle to the AppKernel.php:

```
new BlueTea\AjaxResponseBundle\BlueTeaAjaxResponseBundle(),
```

Implementation
--------------

[](#implementation)

This bundle is implemented automatically in the backend via the AjaxResponseListener. The frontend implementation should be done manually.

### Frontend

[](#frontend)

First we should load the javascript files including jQuery, jQuery-ui, Pnotify and BlockUI.

```

```

or with assetic:

```
{% javascripts combine=true
    '@BlueTeaAjaxResponseBundle/Resources/public/vendor/jquery/dist/jquery.min.js'
    '@BlueTeaAjaxResponseBundle/Resources/public/vendor/jquery-ui/ui/minified/jquery-ui.min.js'
    '@BlueTeaAjaxResponseBundle/Resources/public/vendor/blockui/jquery.blockUI.js'
    '@BlueTeaAjaxResponseBundle/Resources/public/vendor/pnotify/pnotify.core.js'
    '@BlueTeaAjaxResponseBundle/Resources/public/vendor/pnotify/pnotify.buttons.js'
    '@BlueTeaAjaxResponseBundle/Resources/public/vendor/pnotify/pnotify.callbacks.js'
    '@BlueTeaAjaxResponseBundle/Resources/public/vendor/pnotify/pnotify.confirm.js'
    '@BlueTeaAjaxResponseBundle/Resources/public/vendor/pnotify/pnotify.desktop.js'
    '@BlueTeaAjaxResponseBundle/Resources/public/vendor/pnotify/pnotify.history.js'
    '@BlueTeaAjaxResponseBundle/Resources/public/vendor/pnotify/pnotify.nonblock.js'
    '@BlueTeaAjaxResponseBundle/Resources/public/vendor/pnotify/pnotify.reference.js'
    '@BlueTeaAjaxResponseBundle/Resources/private/js/bluetea/ajaxProtocol.js'
    '@BlueTeaAjaxResponseBundle/Resources/private/js/bluetea/arrayMerge.js'
    '@BlueTeaAjaxResponseBundle/Resources/private/js/bluetea/blockUi.js'
    '@BlueTeaAjaxResponseBundle/Resources/private/js/bluetea/bootstrapModal.js'
%}

{% endjavascripts %}

{% stylesheets filter="cssrewrite"
    '@BlueTeaAjaxResponseBundle/Resources/public/jquery-ui/themes/smoothness/jquery-ui.min.css" rel="stylesheet'
    '@BlueTeaAjaxResponseBundle/Resources/public/vendor/pnotify/pnotify.core.css'
    '@BlueTeaAjaxResponseBundle/Resources/public/vendor/pnotify/pnotify.buttons.css'
    '@BlueTeaAjaxResponseBundle/Resources/public/vendor/pnotify/pnotify.history.css'
    '@BlueTeaAjaxResponseBundle/Resources/public/vendor/pnotify/pnotify.picon.css'
%}

{% endstylesheets %}
```

Then initialize the ajaxProtocol and blockUi widgets.

```
$(function () {
    $(document).ajaxProtocol();
    $(document).blockUi();
});
```

Usage
-----

[](#usage)

### Backend

[](#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.

```
return new AjaxResponse($content = '', $type = self::TYPE_DATA, $data = null, $status = 200, $headers = array())
```

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:

```
return new AjaxResponse(
    $this->renderView('AcmeDemoBundle:Example:show.html.twig',
        $data
    ),
    AjaxResponse::TYPE_MODAL
);
```

And if you want to fire an event in javascript:

```
return new AjaxResponse('your_event_name', AjaxResponse::TYPE_EVENT, $additional_data);
```

All possible AjaxResponse types:

```
// An empty response
return new AjaxResponse();

// Just some data
return new AjaxResponse($yourData);

// Trigger an javascript event
return new AjaxResponse('your_event_name', AjaxResponse::TYPE_EVENT, $optional_data);

// Redirect
return new AjaxResponse('http://your-url.com', AjaxResponse::TYPE_REDIRECT);

// Render Bootstrap modal
return new AjaxResponse('', AjaxResponse::TYPE_MODAL);

// Render Bootstrap modal with twig rendering
return new AjaxResponse($this->renderView('your-view', $data), AjaxResponse::TYPE_MODAL);
```

Don't pre-serialize the data. The data is serialized to JSON by the AjaxResponseListener.

### Frontend

[](#frontend-1)

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:

```
$(document).ajaxProtocol({
    url: null,
    data: null,
    type: 'POST',
    beforeSendCallback: function() { $(window).application('blockUI'); },
    readyCallback: function() { $(window).application('unblockUI'); },
    successCallback: function() {},
    failCallback: function() { bootbox.alert('Oh god! Something went terribly wrong :-('); }
});
```

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:

```
$(document).ajaxProtocol("call", {url: url, type: 'GET'});
```

Example for an event:

```
$(document).ajaxProtocol("call", {url: url, type: 'GET'});
```

Example for posting data:

```
$(document).ajaxProtocol("call", {url: url, type: 'POST', data: {foo: 'bar'});
```

Example when using dataTables:

```
"fnServerData": function ( sSource, aoData, fnCallback ) {
    $(document).ajaxProtocol("call", {
        url: sSource,
        data: aoData,
        type: 'GET',
        successCallback: function(data) { fnCallback(data) },
        beforeSendCallback: null // disable the blockUI by overriding this callback
    });
},
```

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 57.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~188 days

Recently: every ~412 days

Total

11

Last Release

2287d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a64fbad5c4336c0803f3e06eebb1949d3c11f7b98d46d7e188b9e7f6adbb4645?d=identicon)[piwi91](/maintainers/piwi91)

![](https://www.gravatar.com/avatar/ba49703b912f9a3e5aefe304feea8815a9eaca332c7af2d16c835c838e7320ee?d=identicon)[bluetea](/maintainers/bluetea)

---

Top Contributors

[![piwi91](https://avatars.githubusercontent.com/u/667095?v=4)](https://github.com/piwi91 "piwi91 (4 commits)")[![Nyrris](https://avatars.githubusercontent.com/u/6594063?v=4)](https://github.com/Nyrris "Nyrris (2 commits)")[![metalmini](https://avatars.githubusercontent.com/u/510652?v=4)](https://github.com/metalmini "metalmini (1 commits)")

---

Tags

responseSymfony2ajaxhttp-foundationhttpfoundationajaxresponseajax-response

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bluetea-ajax-response-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/bluetea-ajax-response-bundle/health.svg)](https://phpackages.com/packages/bluetea-ajax-response-bundle)
```

###  Alternatives

[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.3k63.6M232](/packages/nelmio-api-doc-bundle)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M235](/packages/api-platform-core)[friendsofsymfony/http-cache-bundle

Set path based HTTP cache headers and send invalidation requests to your HTTP cache

43813.2M47](/packages/friendsofsymfony-http-cache-bundle)[illuminate/http

The Illuminate Http package.

11936.0M5.0k](/packages/illuminate-http)[playbloom/guzzle-bundle

Provide Symfony2 web profiler for Guzzle

82311.0k1](/packages/playbloom-guzzle-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
