retorno de json_encode inválido
Boa tarde galera do imarsters.
Tenho uma classezinha que faz retorno do php em json
<?php
/ Database connection start /
$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
/ Database connection end /
// storing request (ie, get/post) global array to a variable
$requestData= $_REQUEST;
$columns = array(
// datatable column index => database column name
0 =>'razao_social',
1 =>'nome',
2 => 'cargo',
3 => 'tel_comercial1',
4 => 'tel_celular1',
5 => 'email1',
6 => 'id_resp'
);
// getting total number records without any search
$sql.="SELECT razao_social,nome,cargo,tel_comercial1,tel_celular1,email1,id_resp";
$sql.=" FROM responsibles_view";
$query=mysqli_query($conn, $sql) or die("Erro");
$totalData = mysqli_num_rows($query);$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.
$sql = "SELECT razao_social,nome,cargo,tel_comercial1,tel_celular1,email1,id_resp ";
$sql.=" FROM responsibles_view WHERE 1 = 1";
if(!empty($requestData['search']['value'])){
$sql.=" AND razao_social LIKE '%".$requestData['search']['value']."%'".
"OR nome LIKE '%".$requestData['search']['value']."%'".
"OR cargo LIKE '%".$requestData['search']['value']."%'".
"OR tel_comercial1 LIKE '%".$requestData['search']['value']."%'".
"OR tel_celular1 LIKE '%".$requestData['search']['value']."%'".
"OR email1 LIKE '%".$requestData['search']['value']."%'";
//"OR id_resp LIKE '%".$requestData['search']['value']."%'";
}/*
if(!empty($requestData['columns'][15]['search']['value'])){
$sql.=" AND razao_social LIKE '".$requestData['columns'][15]['search']['value']."%' ";
}*/
$query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees");
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." "; // adding length
$query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees");
$data = array();
while( $row=mysqli_fetch_array($query) ) { // preparing an array
$nestedData=array();
$nestedData[] = $row["razao_social"];
$nestedData[] = $row["nome"];
$nestedData[] = $row["cargo"];
$nestedData[] = $row["tel_comercial1"];
$nestedData[] = $row["tel_celular1"];
$nestedData[] = $row["email1"];
$nestedData[] = "<a href='detail-license.php?id=".$row['id_resp']."'><button class='btn btn-success'><i class='fa fa-list'></i> Detalhes</button></a>";
$data[] = $nestedData;
}
$json_data = array(
"draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval( $totalData ), // total number of records
"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
Uma view com os campos selecionados 'razao_social','nome','cargo',tel_comercial1',tel_celular1',email1',id_resp' e está dando retorno inválido. Quando eu abro o chrome, diz que this request has no response data available
Discussão (24)
Carregando comentários...