查询参数 bootstrap table

queryParams bootstrap table

我正在像这样在 div 中创建我的 table:

var tabla = $('<table id="tablaConteo2"></table>');
var thead = $('<thead></thead>');
var enc = $('<tr> <th></th> <th></th> <th></th> <th></th> <th></th> </tr>');
thead.appendTo(tabla);
enc.appendTo(thead);
tabla.appendTo('#tablaDatosToma2');
var $tabla = $('#tablaConteo2');

然后我使用 this library 像这样初始化 table:

$tabla.bootstrapTable({
                    height: 200,
                    url: 'BuscarCodigo',
                    method: 'post',
                    queryParams: function(p){
                    return{
                        codigoProducto : $('#codigoToma2').val(),
                        bodegaID: $('#bodega').val()
                    };

                },
                pagination: true,
                pageSize: 50,
                pageList: [10, 25, 50, 100, 200],
                showRefresh: true,
            columns: [
            {
                field: 'codigoProducto',
                title: 'C\u00F3digo'
            }, 
            {
                field: 'cantidad',
                title: 'Cant. Actual',
                width: '200px'
            },
            {
                field: 'nuevaCantidad',
                title: 'Cantidad'
            },
            {
                field: 'bodega',
                title: 'Bodega'
            },
            {
                field: 'estanteria',
                title: 'Estanter\u00EDa'
            },
            {
                field: 'seccion',
                title: 'Secci\u00F3n'
            },
            {
                field: 'estanteriaID',
                title: 'Estanter\u00EDa'
            },
            {
                field: 'seccionID',
                title: 'Secci\u00F3n'
            }
            ]
            });

在我的 servlet 上,我像往常一样获取参数,如下所示:

request.getSession().setAttribute("codigoProducto", request.getParameter("codigoProducto"));
request.getSession().setAttribute("bodegaID", request.getParameter("bodegaID"));

servlet 正在执行,但是当我尝试使用参数时它们是空的,谁能帮助找出我做错了什么。

您可以将contentType选项设置为application/x-www-form-urlencoded,因为默认值为application/json:

$tabla.bootstrapTable({
    method: 'post',
    contentType: 'application/x-www-form-urlencoded',
    ...
});

这是一个相关问题:https://github.com/wenzhixin/bootstrap-table/issues/918