-1
I’m having trouble accessing a class via $.post from jquery. There is some internal error that is not shown in the console. If I instantiate the class via php, it works perfectly, just by jquery that does not return anything. I am using spl_autoload in index only.
Controllers/Funilcontroller.php
<?php
namespace Controllers;
use Models\Vendas;
class FunilController
{
public function __construct()
{
$v = new Vendas;
$vendas = $v->index();
return $vendas
}
}
Models/Sales.php
<?php
namespace Models;
use Models\Conexao;
class Vendas extends Conexao
{
public function index()
{
return 'olá';
}
}
index php.
<?php
spl_autoload_register(function( $class ) {require_once str_replace( '\\', DIRECTORY_SEPARATOR, $class ) . '.php';});
?>
(...)
<script>
$.post('Models/Vendas.php',
{solicitar: true, tab:1, cpf: Cpf, data_ini: dataIni, data_fim: dataFim},
function(data){
$('#res1').empty().append(data);
}, 'json');
</script>
I don’t know why, but it’s not sending the data via post: $. ajax({ type: "POST", url: "Controllers/Jsoncontroller.php", data: { prompt: true, tab:4, Cpf: Cpf, data_ini: dataIni, data_end: dataFim ;contenttype: "application/json", beforeSend: Function(){ console.log('sending...'+Cpf); } }) . done(Function(msg){ console.log(msg); }) . fail(Function(jqXHR, textStatus, msg){ console.log(msg); });
– Glenys Mitchell
Isn’t it coming in the backend? Or Voce isn’t having a comeback??
– Claudio H. Yoshii
It’s coming, why I managed to return hello, just not receiving the data passed by post there.
– Glenys Mitchell
Oh yes, dataType (string), I updated the code, see if it’s right... The backend is returning a "hello"??
– Claudio H. Yoshii
Still not receiving the post, is returning the 'out': if(isset($_POST['request']) or isset($_POST['Cpf']) { echo json_encode('here'); } Else { echo json_encode('out'); }
– Glenys Mitchell
I’m starting to think the problem isn’t in the post.
– Claudio H. Yoshii
Do you usually use namespace in your projects? Why is it the first time I’m using it and is giving it away =/
– Glenys Mitchell
@Glenysmitchell does so try the post, by Postman, then we will see where the error is...
– Claudio H. Yoshii