0
I am trying to return the result of a query via ajax with php and jquery, but it is not working, I get a parser error message and am unable to identify the problem.
FUNCAO JS
function buscaCliente() {
var cnpj = $('#cnpjCliente').val();
$.ajax({
url: "buscaCliente.php",
method: "POST",
data: {'cnpj':cnpj},
dataType: "JSON"
}).done(function(response) {
console.log(JSON.parse(response));
}).fail(function(jqXHR, textStatus ) {
console.log("Request failed: " + textStatus);
}).always(function() {
console.log("completou");
});
}
PHP SEARCH CLIENT.
<?php
require_once 'pdo.php';
$cnpjCliente = filter_input(INPUT_POST,'cnpj');
$sql = "SELECT nome
FROM php.clientes
WHERE cnpj = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$cnpjCliente]);
$nome = $stmt->fetch();
echo json_encode($nome);
?>
ERROR MESSAGE
Request failed: parsererror
If possible display the error that is returning
– Marciano Machado