Kelvin Primo Kelvin Primo - 4 months ago 32x
Ajax Question

how to render ajax return in cakephp 3.1

I have a table that have checkboxes inside. after select it how to return a sum of values from table in modal before confirm the form? and how to render the ajax response from controller?
in my view

url: '../vendas/confirmar',
type: 'post',
success: function (data) {

in my controller

$sum = $sum;
$this->render('ajax/confirmado', 'ajax');
echo 'bal';
$this->set('text', 'test');
$this->set('_serialize', ['text']);


how to print the result in the view without reloading page?


What this fiddle does is grabs all of your inputs, then pops up a modal after the values and names have been injected for confirmation.

It should give you a good starting point. What this is setup to do is give you the confirmation screen without the need for additional server calls.

Just set your action to the route that you want to pass the information to for server interactions.


<form id="test-form" method="post" action="your/action/here">
  <input type="text" name="test" value="" />
  <input type="submit" name="submit-form" value="submit" />

<div class="modal">
  <div class="form-info-wrapper">

  <a class="confirm">Confirm Information</a>


.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  background: #FFF;


jQuery(document).ready(function ($){
    $('body').on('click', 'input[type=submit]', function (e) {

    var data = $(this).parent('form').serializeArray();


    for(_data in data)
        $('.form-info-wrapper').append(data[_data].name + ': ' + data[_data].value);


  $('.confirm').click(function (e){