duanke0178 2016-06-06 19:34
浏览 58
已采纳

如何在cakephp 3.1中渲染ajax返回

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

    $("#envia-vendas").ajaxForm({
  url: '../vendas/confirmar', 
  type: 'post', 
  success: function (data) {
    $('#myModal').modal('show');
    console.log(data);
  },

in my controller

//dostuf
            if($this->request->is('ajax')){
              $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?

  • 写回答

1条回答 默认 最新

  • ds11111111111111111 2016-06-06 20:55
    关注

    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.

    HTML

    <form id="test-form" method="post" action="your/action/here">
      <input type="text" name="test" value="" />
      <input type="submit" name="submit-form" value="submit" />
    </form>
    
    <div class="modal">
      <div class="form-info-wrapper">
    
      </div>
      <a class="confirm">Confirm Information</a>
    </div>
    

    CSS

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

    JS

    jQuery(document).ready(function ($){
        $('body').on('click', 'input[type=submit]', function (e) {
        e.preventDefault();
    
        var data = $(this).parent('form').serializeArray();
    
        $('.form-info-wrapper').empty();
    
        for(_data in data)
        {
            $('.form-info-wrapper').append(data[_data].name + ': ' + data[_data].value);
        }
    
        $('.modal').fadeIn();
      });
    
      $('.confirm').click(function (e){
            e.preventDefault();
    
        $('#test-form').submit();
      });
    });
    

    https://jsfiddle.net/ojaeacps/2/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序 用oss下载 aliyun-oss-sdk-6.18.0.min client报错
  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。
  • ¥15 抖音看过的视频,缓存在哪个文件