Good morning classmates, I'm doing a web program and I have a problem sending a variable via jquery and javascript.
I have the following method that redirects and sends a variable by this address:
function consultarPaciente(){
url = "index.php?accion=consultarPaciente&documento="+$("#asignarDocumento").attr('value');
$("#paciente").load(url);
/* alert($("#asignarDocumento").attr('value'));*/
}
the code that I have commented on I do to know what value comes to me in the execution which indicates that it is undefined.
The html that uses this code is the following:
<html>
<head>
<meta charset="UTF-8" content="text/html" http-equiv="Content-Type">
<title>Sistema Gestion Odontologica</title>
<link href="Vista/css/estilos.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="Vista/jquery/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="Vista/js/script.js"></script>
</head>
<body>
<div id="contenedor">
<div id="encabezado">
<img src="Vista/imagenes/odontologia.png" width="100%" height="150px" >
</div>
<ul id="menu">
<li><a href="index.php">Inicio</a></li>
<li class="activa"><a href="index.php?accion=asignar">Asignar Cita</a></li>
<li><a href="index.php?accion=consultar">Consultar Cita</a></li>
<li><a href="index.php?accion=cancelar">Cancelar Cita</a></li>
</ul>
<div id="contenido">
<h2 style="width:100%">Asignar Cita</h2>
<form id="frmAsignar" method="POST" action="index.php?accion=guardarCita">
<table>
<tr>
<td>Documento del Paciente</td>
<td><input type="text" name="asignarDocumento" id="asignarDocumento"></td>
</tr>
<tr>
<td colspan="2">
<input type="button" name="asignarConsultar" value="Consultar" id="asignarConsultar" onclick="consultarPaciente()">
</td>
</tr>
As you can see I consult first if the patient is there and I do it with the javascript function.
<tr>
<td>Documento del Paciente</td>
<td><input type="text" name="asignarDocumento" id="asignarDocumento"></td>
</tr>
<tr>
<td colspan="2">
<input type="button" name="asignarConsultar" value="Consultar" id="asignarConsultar" onclick="consultarPaciente()">
</td>
</tr>
The javascript function redirects me to the main page called index.php that executes functions in the Controller and GestorCita class.
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
require_once 'Controlador/Controlador.php';
require_once 'Modelo/GestorCita.php';
require_once 'Modelo/Cita.php';
require_once 'Modelo/Paciente.php';
require_once 'Modelo/Conexion.php';
$controlador = new Controlador();
if(isset($_GET['accion'])){
if($_GET['accion'] == 'asignar'){
$controlador->verPagina('Vista/html/asignar.php');
}
elseif($_GET['accion'] == 'consultar'){
$controlador->verPagina('Vista/html/consultar.php');
}
elseif ($_GET['accion'] == 'cancelar') {
$controlador->verPagina('Vista/html/cancelar.php');
}
elseif ($_GET['accion'] == 'guardarCita') {
$controlador->agregarCita($_POST['asignarDocumento'], $_POST['medico'],
$_POST['fecha'], $_POST['hora'], $_POST['consultorio']);
}
elseif($_GET['accion'] == 'consultarCita'){
$controlador->consultarCitas($_POST['consultarDocumento']);
}
elseif ($_GET['accion'] == 'cancelarCita') {
$controlador->cancelarCita($_POST['cancelarDocumento']);
}
elseif ($_GET['accion'] == 'consultarPaciente') {
$controlador->consultarPaciente($_GET['documento']);
}
else{
$controlador->verPagina('Vista/html/inicio.php');
}
}
else{
$controlador->verPagina('Vista/html/inicio.php');
}
?>
</body>
Here is the method to consult Patient in the controller class which is instantiated in the index.php.
#metodo consultar paciente
public function consultarPaciente($doc) {
$gestorCita = new GestorCita();
$result = $gestorCita->consultarPaciente($doc);
require_once 'Vista/html/consultarPaciente.php';
}
and here is the GestorCita class which is instantiated in the previous controller class.
#metodo consultar paciente
public function consultarPaciente($doc) {
$gestorCita = new GestorCita();
$result = $gestorCita->consultarPaciente($doc);
require_once 'Vista/html/consultarPaciente.php';
}
When executing a user in the browser, it is entered in the database and it appears that it is not entered.
. The problem that I detect is that the 'document' value is not coming to me since when printing it it appears to me as undefined.
note: the connection and the query already verify them and they work normally since I have other queries and I have no problems.
Thank you very much for any help I'm starting in this and to be any problem but you know how it is at the beginning.