mabs/jquery-ajax-bundle

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

Installs: 221

Dependents: 0

Suggesters: 0

Security: 0

Stars: 6

Watchers: 2

Forks: 2

Open Issues: 0

Type:symfony-bundle

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

This package is not auto-updated.

Last update: 2024-03-16 11:09:41 UTC


README

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.