This bundle provides a Twig functions that generate js function to send ajax request.

Installs: 137

Dependents: 0

Stars: 6

Watchers: 2

Forks: 1

Language: PHP

v1.1 2014-02-19 16:21 UTC


Build Status Scrutinizer Code Quality GitHub issues GitHub stars GitHub license

JQueryAjaxBundle for Symfony2.


To install this bundle on your project, add this line to composer.json file:

   "mabs/jquery-ajax-bundle": "~1.0"

This bundle add two Twig functions:

1 - ja_request:

To generate a js code to send an ajax request:

  {{ ja_request({'update': '#reponse', 'url': path('new')  }) }}


{{ ja_request({'update': '#reponse', 'url': path('new'), 'after': 'alert("after");', 'before': 'alert("before");', 'complete': 'alert("complete");'  }) }}


  $.ajax({ url: "/app_dev.php/new", type: "POST", dataType: "html",beforeSend: function(){alert("before");},success: function( data ){$( "#reponse" ).html(data);alert("after");}});

2 - ja_link:

To generate a link:

  {{ ja_link({'update': '#reponse', 'url': path('new'), 'text': 'new link'  }) }}

To add a confirm action on click, you just have to use 'confirm': true, by default the text is "Are you sure you want to perform this action?" then if you want to replace it, use 'confirm_msg': "***".

You can also use those parameters 'before' and 'after' to execute JS code.

3 - License

This bundle is available under the MIT license.