0
I don’t get Json feedback in Ajax. Any idea what it might be?
Ajax.js
$.ajax({
type: 'POST',
dataType: 'json',
url: "crud/insere.php",
data: dados,
success: function(data) {
var objeto = JSON.parse(data);
alert(objeto.id);
}
});
return false;
php insert.
$nome = $_POST['nome'];
$telefone1 = $_POST['telefone1'];
$operadora1 = $_POST['operadora1'];
$telefone2 = $_POST['telefone2'];
$operadora2 = $_POST['operadora2'];
$email = $_POST['email'];
$cidade = $_POST['idCidade'];
$observacao = $_POST['obs'];
$dataCadastro = date('Y-m-d H:i:s');
if(empty($cidade)){
$cidade = '0';
}
$select = "INSERT INTO Cliente(nome, telefone1, telefone2, operadora1, operadora2,
email, idCidade, observacao, dataCadastro)
VALUES ('$nome', '$telefone1', '$telefone2', '$operadora1', '$operadora2', '$email', '$cidade','$observacao', '$dataCadastro')";
$conexao = conexao();
$PDO=$conexao->prepare($select);
$PDO->execute();
$select = "SELECT id FROM Cliente WHERE email='$email'";
$PDO=$conexao->prepare($select);
$PDO->execute();
$obj = $PDO -> fetch(PDO::FETCH_OBJ);
$arr = array('id' => $obj->id);
echo json_encode($arr);insira o código aqui
Complete Code
Is the record being entered in the database? Is PHP showing an error? Is the Javascript "data" variable being filled in with the form data correctly? We need more details to help. A good tool for testing Apis is POSTMAN, plugin for Google Chrome. In it you simulate the HTTP call (Ajax) and view the return of the server.
– NewtonWagner
The records are recording in the bank, the console does not present any error. I believe it is filling right, you can check on the image of the full source. Some other idea?
– Alisson Hoepers
Just looking at the code I could not think of anything. What I suggest is to install POSTMAN and simulate the call. You can even debug the code in the process.
– NewtonWagner
It seems that the POSTMAN plugin address is out, do not load here.
– Alisson Hoepers