I'm trying to build a json from an ajax query, and I try to put it in a Datatable and I get this error in the browser "DataTables warning: table id = example - Invalid JSON response. See http://datatables.net/tn/1 ", I do not know what I can do, help would help me a lot, thank you very much. I'm using Mongo as a database where I look for the relationship to get your id and send that id and get the detail and its attachment to arm the row of the table.
$(document).ready(function() {
var jsonObj = [];
$.ajax({
type: "GET",
url: "/obtenerRelacion",
dataType: "json",
success: function(relacion){
for(var i in relacion) {
var id = relacion[i].cajaChica._id;
$.ajax({
type: "GET",
url: "/obtener/detalle/anexo/"+id+"",
dataType: "json",
success: function(cajaChica){
for(var j in cajaChica) {
item = {};
item['hechoPor'] = relacion[i].cajaChica.HECHO_POR_CORREO;
item['aprobadoPor'] = relacion[i].cajaChica.APROBADO;
item['categoria'] = cajaChica[j].NOMBRE_CATEGORIA;
item['valor'] = cajaChica[j].VALOR
item['ruc_ced'] = cajaChica[j].RUC_CED;
item['fecha'] = cajaChica[j].FECHA;
item['empresa'] = cajaChica[j].NOMBRE_EMPRESA;
item['entregadoA'] = cajaChica[j].NOMBRE_ENTREGADO;
item['proveedor'] = cajaChica[j].NOMBRE_PROVEEDOR;
item['cargadoA'] = cajaChica[j].NOMBRE_CARGADO;
item['detalle']= cajaChica[j].DETALLE_CAJA;
if(cajaChica[j].anexo != undefined){
item['tipo'] = cajaChica[j].anexo['TIPO'];
item['numFact'] = cajaChica[j].anexo['ESTAB_FAC']+''+cajaChica[j].anexo['PTO_FAC']+''+cajaChica[j].anexo['SEC_FAC'];
}else{
item['tipo'] = 'NO HAY';
item['numFact'] = 'NO EXISTE'
}
jsonObj.push(item);
}
}
});
}
},
complete: function(){
$('#table').DataTable( {
ajax: jsonObj,
columns: [
{ title: "aprobadoPor" },
{ title: "cargadoA" },
{ title: "categoria" },
{ title: "detalle" },
{ title: "empresa" },
{ title: "entregadoA" },
{ title: "fecha" },
{ title: "hechoPor" },
{ title: "proveedor" },
{ title: "ruc_ced" },
{ title: "tipo" },
{ title: "valor" },
{ title: "numFact"}
]
});
}
});
});
via Bakke Medina
No comments:
Post a Comment