1. Go to this page and download the library: Download manuelj555/ajax-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
manuelj555 / ajax-bundle example snippets
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new Ku\AjaxBundle\KuAjaxBundle(),
// ...
);
}
public function createAction(Request $request)
{
$user = new User();
$form = $this->createForm(new UserType(), $user, array(
'action' => $request->getRequestUri(),
));
$form->handleRequest($request);
if ($form->isSubmitted() and $form->isValid()) {
$this->get('fos_user.user_manager')
->updateUser($user);
$this->addFlash('success', 'User Created!');
$this->get('ku_ajax.handler')->success();
// Calling to succes method on ajax Handler, stop the redirection on ajax request
// and send a status code 200
return $this->redirectToRoute('admin_company_users_list', array('companyId' => $company->getId()));
}elseif($form->isSubmitted()){
// invalid form
$this->get('ku_ajax.handler')->badRequest();
// this send a status code 400
}
return $this->render('user/create.html.twig', array(
'form' => $form->createView(),
));
}