Dear I have an ajax that brings me data from the database with php to a table the code is the following
Ajax:
$('#selplan').change(function(){
var idplan = $('#selplan').val();
var consulta = $.ajax({
type: 'Post',
url: '../Model/buscarplan.php',
data: {plan: idplan},
dataType: 'JSON'
});
consulta.done(function (data) {
if ( data && data.error !== undefined) {
$('#estado').html('Ha ocurrido un error: ' + data.error);
return false;
} else {
if (data.Minutos !== undefined) {
$('#datosplan #txtMinutos').val(data.Minutos);
}
if (data.Datos !== undefined) {
$('#datosplan #txtDatos').val(data.Datos);
}
return true;
}
});
consulta.fail(function () {
$('#estado').html('Ha habido un error contactando el servidor.');
return false;
});
})
my php:
<?php namespace Model;
$conexion = new \mysqli("localhost", "", md5(''), "");
if ($conexion->connect_error) {
echo "Fallo al conectar:".$conexion->connect_error() or die();
}
if (! empty($_POST['plan'])) {
$idplan = $_POST['plan'];
$query = "SELECT IdPlan,Nombre,Minutos,Datos FROM plan WHERE IdPlan = $idplan";
$result = $conexion->query($query);
die(json_encode($result->fetch_array()));
}
$conexion->close();
before I had two records in that table and I looked well and I load the data but I added a third record and that special does not bring me the data returns null, any suggestions? here I hit the error
Validate.js: 96 Uncaught TypeError: Can not read property 'Minutes' of null at Object. (Validate.js: 96) at i (jquery.min.js: 2) at Object.fireWith [as resolveWith] (jquery.min.js: 2) at A (jquery.min.js: 4) at XMLHttpRequest. (jquery.min.js: 4)