Uncaught SyntaxError: Unexpected token {
Uncaught SyntaxError: Unexpected token {
User123456
Posts: 57Questions: 15Answers: 0
I was doing the code below, howerever, it's not shown as expected and returns:
Uncaught SyntaxError: Unexpected token {
I want that if p.status be equals to 1 return a green circle(<i class='ace-icon fa fa-circle green'></i>) else return a red circle(<i class='ace-icon fa fa-circle red'></i>).
Data is correctly returned as seen in the network.
This is my code from bootstrap.html:
<script type="text/javascript" language="javascript" class="init">
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
ajax: "../php/staff.php",
table: "#publicationTable",
fields: [ {
label: "Visualizado:",
name: "p.id_Publication"
}, {
label: "Título da Publicação:",
name: "ti.PublicationTitle"
}, {
label: "Tipo de Publicação:",
name: "ty.PublicationType"
}, {
label: "Ano:",
name: "p.ano"
}, {
label: "Mês:",
name: "p.competencia"
}, {
label: "Empresa:",
name: "c.razaoSocial"
}, {
label: "Favorecido:",
name: "e.nome"
}
]
} );
var table = $('#publicationTable').DataTable( {
lengthChange: true,
ajax: "../php/staff.php",
columns: [
{ data: "p.status",
render: function ( data, type, row ) {
var text = "";
if (type == "display") {
if (data == "1") {
text = "<i class='ace-icon fa fa-circle green'></i>";
} else {
text = "<i class='ace-icon fa fa-circle red'></i>";
}
data = text
}
return data;
},
}
{ data: "ti.PublicationTitle" },
{ data: "ty.PublicationType" },
{ data: "p.ano" },
{ data: "p.competencia" },
{ data: "c.razaoSocial" },
{ data: "e.nome" }
],
} );
} );
</script>
And from staff.php:
<?php
include( "../../php/Datatables.php" );
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
Editor::inst( $db, 'tbl_publication AS p', 'id_Publication' )
->fields(
Field::inst( 'p.status' ),
Field::inst( 'ti.PublicationTitle' ),
Field::inst( 'ty.PublicationType'),
Field::inst( 'p.ano' ),
Field::inst( 'p.competencia' ),
Field::inst( 'c.razaoSocial' ),
Field::inst( 'e.nome')
)
->leftJoin( 'tbl_ptitle AS ti', 'p.fk_titulo', '=', 'ti.id_PublicationTitle' )
->leftJoin( 'tbl_ptype AS ty', 'p.fk_tipo', '=', 'ty.id_PublicationType' )
->leftJoin( 'tbl_company AS c', 'p.fk_empresa', '=', 'c.id_Company' )
->leftJoin( 'tbl_employee AS e', 'p.fk_empregado', '=', 'e.id_Employee' )
->process($_POST)
->json();
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
This is a syntax error in your JS code. You can look at the browsers console to see the error and which line. It looks like this is the error:
Kevin