0
can’t get out of place, what’s wrong? I don’t get the feedback from Json in Ajax.
register Customer.php
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);
This line is not needed because you already said it is type:json,
var objeto = JSON.parse(data);
. In terms of database security entering the values like this is very insecure, but maybe you’re just testing.– Sergio
Even so, nothing happens, not even in the browser console.
– Alisson Hoepers
Dude, if you have an example that works and you can send it to me,.
– Alisson Hoepers