Javascript Bootgrid读取JSON中的返回值
我使用jquerybootgrid在表中显示数据。我使用Ajax获取数据,并以JSON格式返回值。JSON字符串中有一个变量,我想读取该变量以显示在表外的其他部分中 Ajax功能如下所示:Javascript Bootgrid读取JSON中的返回值,javascript,ajax,jquery-bootgrid,Javascript,Ajax,Jquery Bootgrid,我使用jquerybootgrid在表中显示数据。我使用Ajax获取数据,并以JSON格式返回值。JSON字符串中有一个变量,我想读取该变量以显示在表外的其他部分中 Ajax功能如下所示: function ajaxAction(action) { data = $("#frm_"+action).serializeArray(); $.ajax({ type: "POST", url:
function ajaxAction(action) {
data = $("#frm_"+action).serializeArray();
$.ajax({
type: "POST",
url: "response_pedidos.php",
data: data,
dataType: "json",
success: function(response)
{
$('#'+action+'_model').modal('hide');
$("#employee_grid").bootgrid('reload');
},
error: function (request, error) {
console.log(arguments);
}
}); }
我正在观看PHP页面的响应,其格式如下:
{"current":1,
"rowCount":20,
"total":7,
"cantidad_totales":8.5,
"id_pedido":13,
"rows":[{"id_pedidos_productos" :"57",
"cantidad":"1.5",
"descripcion":"prueba con decimales",
"nombre":"Astro naranja"},
{"id_pedidos_productos":"52",
"cantidad":"1",
"descripcion":"",
"nombre":"Gipso grande"},
{"id_pedidos_productos":"54",
"cantidad":"1",
"descripcion":"",
"nombre":"Lilis Rosita"},
{"id_pedidos_productos":"53",
"cantidad":"1",
"descripcion" :"",
"nombre":"Plumosos"},
{"id_pedidos_productos":"56",
"cantidad":"1",
"descripcion":"",
"nombre":"ROSAS BABY VENDELA"},
{"id_pedidos_productos":"55",
"cantidad":"1",
"descripcion":"",
"nombre":"Rosas rojas"},
{"id_pedidos_productos":"51",
"cantidad":"2",
"descripcion":"",
"nombre":"ROSAS ROSITAS \"MATIZADAS\"" }]}
在页面上,我的表格如下所示,我希望在表格下方的字段中显示获得的值:
现在,我要做的是读取名为:cantidad_totales的返回值
我想捕捉它显示在页面的简历部分
有人知道我该怎么做吗?这是您可以处理的方式:
var cantidadTotales;
$('#tbl').bootgrid({
formatters:{
...
},
rowCount: [5, 10, 25],
...
labels: {
....
},
css: {
...
},
responseHandler: function (data) {
var response = {
current: data.current,
rowCount: data.rowCount,
rows: data.rows,
total: data.total,
cantidad_totales: data.cantidad_totales,
id_pedido: data.id_pedido
};
//store cantidad_totales into a variable...
cantidadTotales = data.cantidad_totales;
return response;
},
ajaxSettings: {
method: 'POST',
contentType: 'application/json'
},
ajax: true,
url: 'The_Url_To_Load_Your_Data'
}).on("loaded.rs.jquery.bootgrid", function (s) {
//Now, display the cantidad_totales in your div or whatever
$('div#YourTotalDiv').html(cantidadTotales);
});
})
非常感谢,我不知道respondeHandler和requestHandler。这个函数解决了这个问题,现在我可以观察数据并在表外使用。@zinczi a在相同的情况下,但是响应处理程序没有执行,知道吗?@Bsienn,很抱歉回复太晚了。我已经很久没有使用Bootgrid了。请尝试通过进入>更多工具>开发者工具>控制台Chrome或F12 Edge/IE浏览器来检查客户端的JavaScript或html错误。感谢回复,根本没有错误,我已经切换到datatable,放心了。我不明白你的意思,我不再使用bootgrid,我将当前代码改为ajax中的简单html表,简化了代码,无需搜索排序,只需列出。