Skip to content

kernel64/JQueryAjaxBundle

Repository files navigation

JQueryAjaxBundle SensioLabsInsight


Build Status Scrutinizer Code Quality GitHub issues GitHub stars GitHub license

JQueryAjaxBundle for Symfony2.

Install

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')  }) }}

or

{{ 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.