I am trying to make a record in the BD without recharging the page. The record is saved correctly, but when I want to capture the answer the PHP document is displayed.
Code js
$('#btnagregarO').click(function(){
var obs = $("#txtob").val();
var cliente = $("#txtcli").val();
var datos = "obs="+obs+"&cliente="+cliente;
$.ajax({
type : 'POST',
url : 'Usuario.php',
data : datos,
success:function(resp){
alert(resp);
}
});
event.preventDefault();
});
PHP File:
$u->conexion();
$sql = "insert observacion values(NULL,'$Obs',$N,'$usu','$fecha')";
$sentencia = $u->m->query($sql);
if($u->m->affected_rows > 0){
echo "Se pudo registrar";
}else{
echo "No se pudo registrar";
}
$u->desconexion();
Hopefully help me that first time using ajax and I do not know what can be wrong.