后台传map,前台用bootstrapTable接收数据和用ajax接收数据

使用bootstrap table插件要使用关键字responseHandler来处理后台的返回数据。

这里用map作为示例:

$("#tb_departments").bootstrapTable({
            url: 'queryPrecisionCastDetail.z',
            method: 'post',
            contentType: "application/x-www-form-urlencoded",
            dataType: "json",
            toolbar: '#toolbar',
            striped: true,
            sortable: true,
            resizable: true,
//            cache: false,
//            pagination: true,
//            queryParamsType: '',
            queryParams: function (params) {
                var allData = {
                    currentPage: currentPage,
                    limit: 500,
                    startDate: '<#if startDate ??>${startDate}</#if>',
                    endDate: '<#if endDate ??>${endDate}</#if>',
                    type: "${type}"
                }
                return allData;
            },
//            sidePagination: 'server',
//            pageNumber: 1,
//            pageSize: 500,
//            pageList: [500, 1000, 'ALL'],

            height: trueHeight,
            filterControl: true,
            //处理响应数据
            responseHandler: function (res) {
                totalPage = res.totalPage;
                return eval(res.rows);
            },
如果是ajax,直接点出来就行了

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Bootstrap3中,可以使用jQuery来获取表单数据并转换为Map对象,然后使用Ajax将数据递给后台。以下是一个示例代码: ```html <!-- 在页面中定义一个表单 --> <form id="myForm"> <div class="form-group"> <label for="name">Name:</label> <input type="text" class="form-control" id="name" name="name"> </div> <div class="form-group"> <label for="email">Email:</label> <input type="email" class="form-control" id="email" name="email"> </div> <button type="submit" class="btn btn-primary">Submit</button> </form> <!-- 在页面中引入jQuery和Bootstrap的JavaScript库 --> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> <script> $(document).ready(function() { // 当表单提交时 $('#myForm').submit(function(event) { // 阻止默认的表单提交行为 event.preventDefault(); // 将表单数据转换为Map对象 var formData = {}; $('#myForm').serializeArray().map(function(x){formData[x.name] = x.value;}); // 使用Ajax将数据递给后台 $.ajax({ type: 'POST', url: '/submit', data: formData, success: function(response) { console.log('提交成功'); }, error: function(jqXHR, textStatus, errorThrown) { console.error('提交失败:', textStatus, errorThrown); } }); }); }); </script> ``` 在示例代码中,首先定义了一个表单,其中包含了两个表单项:Name和Email。然后在JavaScript代码中,使用jQuery选择器获取表单元素,并在提交表单时阻止默认的表单提交行为。着,使用jQuery的`serializeArray()`方法将表单数据转换为一个数组,然后使用`map()`方法将数组转换为Map对象。最后,使用jQuery的`ajax()`方法将数据递给后台。在`ajax()`方法中,需要指定请求的类型、URL、数据、成功回调和失败回调。在成功回调中,可以处理提交成功后的业务逻辑;在失败回调中,可以处理提交失败后的业务逻辑。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值