(10-02-2018, 08:23 AM)Pertti Wrote: So it comes up with CodeIgniter 404 page?
I guess without source code for controller or routes file it's hard to say.
You said it's an API - are you using CI Restserver or similar? https://github.com/chriskacerguis/codeig...restserver
I believe that I forgot to tell something very important: I'm making AJAX calls to those methods. They're meant to run as form actions, but called by AJAX. Usually, I have a view with a form where user can select a few filters. Then, on the form's submit event, I send them via AJAX to a function inside the controller. This function then calls the API, and outputs the data either on a table (DataTables/JS Grid) or on a file (CSV/XLSX). I'm getting the error on the first post when I do the AJAX call. However, trying to directly open the related function on the browser produces the same result.
About the controller code, take a look. This is my
routes.php file (I've left out all the comments):
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'auth';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
This is the public method that I call to show the view (it goes on the address bar). It is inside a controller file called
Reports.php. I access it by going on
http://server/reports/storeLatePayment:
PHP Code:
public function storeLatePayment() {
$data = [
'controller' => 'Reports',
'view' => 'storeLatePayment',
'config' => [
'titleContentPage' => 'Listagem Barra I',
'descriptionForm' => 'Lista os clientes que estão com o primeiro pagamento atrasado.',
'breadcrumb' => [
'Reports',
'Listagem Barra I'
],
],
'load' => [
'assets/pages/Reports/StoreLatePayment.js?t=' . time(),
]
];
$this->load->view('index', $data);
}
This is
StoreLatePayment.js file:
Code:
$(document).ready(function () {
"use strict";
let tableB1 = $('#tableBarra1').DataTable({
ajax: base_url + "reports/getStoresLatePaymentTableData",
dom: "<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>>" +
"<'row'<'col-sm-12'tr>><'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
bInfo: true,
autoWidth: true,
bFilter: true,
scrollX: false,
columns: [
{
data: "CPF",
render: function (data) {
data = data.padStart(11, '0');
return data.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/g, "\$1.\$2.\$3\-\$4");
}
},
{data: "NOME"},
{
data: "Valor_Prest",
render: function (data) {
return 'R$ ' + data;
}
},
{
data: "ATRASO",
render: function (data) {
return '<span class="font-18 text-red"><b>' + data + '</b></span>';
}
},
{
defaultContent: "<button type='button' class='btn btn-info btn-sm waves-effect waves-light'>" +
"Detalhes</button>"
}
],
order: [[0, 'asc']],
language: {
lengthMenu: 'Mostrar _MENU_ itens por página',
search: '<i class="fas fa-search"></i>',
paginate: {
previous: '<i class="fas fa-caret-left"></i>',
next: '<i class="fas fa-caret-right"></i>'
},
info: 'Mostrando de _START_ até _END_ de um total de _TOTAL_ entradas.'
}
});
let cpfToSearch = 0;
tableB1.on('click', 'button', function () {
let rowinfo = tableB1.row($(this).parents('tr')).data();
let CPF = rowinfo.CPF;
cpfToSearch = CPF.padStart(11, '0');
CPF = CPF.padStart(11, '0');
CPF = CPF.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/g, "\$1.\$2.\$3\-\$4");
$('.nome').text(rowinfo.NOME);
$('.cpf').text(CPF);
$('.contrato').text(rowinfo.CONTRATO);
$('.data-compra').text(rowinfo.DATA_LANCTO);
$('.vencimento-parcela').text(rowinfo.venctoAberto);
$('.dias-atraso').text(rowinfo.ATRASO + ' dias');
$('.valor-total').text('R$ ' + rowinfo.Valor);
$('.valor-parcela').text('R$ ' + rowinfo.Valor_Prest);
$('.parcela-atraso').text(rowinfo.NUM_PREST + ' de ' + rowinfo.TOTAL_PREST);
$('.produto').text(rowinfo.CodProduto + ' - ' + rowinfo.Mercadoria);
$.post(base_url + 'reports/getClientLastProposalInfo', {cpf: cpfToSearch}, function () {
}).done(function (data) {
data = $.parseJSON(data);
if (data.status) {
$('.tel-residencial').text('(' + data.data.ddd_res + ') ' + data.data.tel_res);
$('.tel-celular').text('(' + data.data.ddd_cel + ') ' + data.data.tel_cel);
$('.tel-comercial').text('(' + data.data.ddd_com + ') ' + data.data.tel_com);
$('.nome-ref1').text(rowinfo.NOME_REF1);
$('.tel-ref1').text('(' + rowinfo.DDD_REF1.trim() + ') ' + rowinfo.TEL_REF1.trim());
$('.nome-ref2').text(rowinfo.NOME_REF2);
$('.tel-ref2').text('(' + rowinfo.DDD_REF2.trim() + ') ' + rowinfo.TEL_REF2.trim());
$('#infoModal').modal();
} else {
showToast('error', 'Erro ao obter informações de contato do cliente selecionado!');
}
});
});
});
The following is the
getStoresLatePaymentTableData, referenced in the JS file above. It lives in the same file as
storeLatePayment method:
PHP Code:
public function getStoresLatePaymentTableData() {
$data = [
'operacao' => $this->session->userData->Operacao,
'grupo' => $this->session->userData->Grupo,
'loja' => $this->session->userData->CodLocal,
'atrasoInicial' => 5,
'atrasoFinal' => 60,
'vencimentoInicial' => date('Ymd', strtotime('first day of last month')),
'vencimentoFinal' => date('Ymd', strtotime('last day of this month'))
];
$storeLatePayment = $this->reportslibrary->storeLatePayment($data);
echo json_encode($storeLatePayment);
}
This is the last method mentioned on this code, getClientLastProposalInfo. I don't know if it is currently working as the
getStoresLatePaymentTableData method is throwing 404 error:
PHP Code:
public function getClientLastProposalInfo() {
$data = [
'cpf' => $this->input->post('cpf')
];
$clientInfo = $this->clientslibrary->lastProposal($data);
echo json_encode($clientInfo);
}
As you can see, they're fairly simple and nothing out of the ordinary.
Do you guys need anything else?