Cambio de estado mediante ajax
Publicado por Julian (4 intervenciones) el 12/03/2021 02:15:52
Hola, he intentado hacer cambio de estado mediante ajax pero aun no lo he logrado. Agradecería que alguien me ayudara así que aqui agrego lo que he estado usando
consultarCategoria.php
Categoria.php
CategoriaDAO.php
consultarCategoria.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
$categoria = new Categoria();
$categorias = $categoria->consultarTodos();
?>
<div class="container pb-1">
<div class="row mt-4 justify-content-center d-flex">
<div class="col-lg-12">
<div class="card text-white pt-4">
<div class="cardAdmin card-header text-center rounded">
<h3>Consultar Categoria</h3>
</div>
<div class="card-body">
<div class="table-responsive contenedor">
<table id="example-table" class="display" style="width:100%;color: black;">
<thead style="color: white;">
<th> Nombre</th>
<th> Estado</th>
<th> Servicios</th>
</thead>
<tbody>
<?php
foreach ($categorias as $categoriaActual) {
echo "<tr>";
echo "<td>" . $categoriaActual->getNombre() . "</td>";
echo "<td>";
echo $categoriaActual->getEstado() == 1 ? "Activo" : "Restringido";
echo "</td>";
echo "<td>";
echo "<a href='index.php?pid= " . encrypt("presentacion/administrador/categoria/editarCategoria.php", $key) . "&id=" . encrypt($categoriaActual->getIdCategoria(), $key) . "' class ='btn btn-sm'><i class='fas fa-edit text-light' data-bs-toggle='tooltip' title='Editar'></i></a>";
echo "<button class='btn btn-sm estado' value='" . $categoriaActual->getIdCategoria() . "'>";
echo $categoriaActual->getEstado() == 1 ? "<i class='fas fa-ban text-light' id='d' data-bs-toggle='tooltip' title='Deshabilitar'></i>" : "<i class='fas fa-check text-light' id='h' data-bs-toggle='tooltip' title='Habilitar'></i>";
echo "</button>";
echo "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
var table = $('#example-table').DataTable({
"destroy": true,
"lengthMenu": [
[5, 10, 25, 50, -1],
[5, 10, 25, 50, "All"]
],
responsive: true,
columnDefs: [{
responsivePriority: 1,
targets: 0
},
{
responsivePriority: 10001,
targets: 1
},
{
responsivePriority: 2,
targets: -1
}
],
"language": {
"url": "//cdn.datatables.net/plug-ins/1.10.15/i18n/Spanish.json"
}
});
new $.fn.dataTable.FixedHeader(table);
obtener_data("#example-table tbody", table);
});
</script>
Categoria.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
require "persistencia/CategoriaDAO.php";
class Categoria{
private $idCategoria;
private $nombre;
private $estado;
private $conexion;
private $CategoriaDAO;
/**
* @return string
*/
public function getIdCategoria()
{
return $this->idCategoria;
}
/**
* @return string
*/
public function getNombre()
{
return $this->nombre;
}
/**
* @return string
*/
public function getEstado()
{
return $this->estado;
}
function Categoria ($pIdCategoria="", $pNombre="", $pEstado="") {
$this -> idCategoria = $pIdCategoria;
$this -> nombre = $pNombre;
$this -> estado = $pEstado;
$this -> conexion = new Conexion();
$this -> CategoriaDAO = new CategoriaDAO($pIdCategoria, $pNombre, $pEstado);
}
function consultar(){
$this -> conexion -> abrir();
$this -> conexion -> ejecutar($this -> CategoriaDAO -> consultar());
$this -> conexion -> cerrar();
$resultado = $this -> conexion -> extraer();
$this -> nombre = $resultado[0];
$this -> estado = $resultado[1];
}
function crear(){
$this -> conexion -> abrir();
$this -> conexion -> ejecutar($this -> CategoriaDAO -> crear());
$this -> conexion -> cerrar();
}
function consultarTodos(){
$this -> conexion -> abrir();
$this -> conexion -> ejecutar($this -> CategoriaDAO -> consultarTodos());
$this -> conexion -> cerrar();
$Categorias = array();
while(($resultado = $this -> conexion -> extraer()) != null){
array_push($Categorias, new Categoria($resultado[0], $resultado[1], $resultado[2]));
}
return $Categorias;
}
function editar(){
$this -> conexion -> abrir();
$this -> conexion -> ejecutar($this -> CategoriaDAO -> editar());
$this -> conexion -> cerrar();
}
function editarEstado(){
$this -> conexion -> abrir();
$this -> conexion -> ejecutar($this -> CategoriaDAO -> editarEstado());
$this -> conexion -> cerrar();
}
function consultarPorPagina($cantidad, $pagina, $orden, $dir){
$this -> conexion -> abrir();
$this -> conexion -> ejecutar($this -> CategoriaDAO -> consultarPorPagina($cantidad, $pagina, $orden, $dir));
$this -> conexion -> cerrar();
$Categoriaes = array();
while(($resultado = $this -> conexion -> extraer()) != null){
array_push($Categoriaes, new Categoria($resultado[0], $resultado[1], $resultado[2]));
}
return $Categoriaes;
}
function consultarTotalRegistros(){
$this -> conexion -> abrir();
$this -> conexion -> ejecutar($this -> CategoriaDAO -> consultarTotalRegistros());
$this -> conexion -> cerrar();
$resultado = $this -> conexion -> extraer();
return $resultado[0];
}
function buscar($filtro){
$this -> conexion -> abrir();
$this -> conexion -> ejecutar($this -> CategoriaDAO -> buscar($filtro));
$this -> conexion -> cerrar();
$Categoriaes = array();
while(($resultado = $this -> conexion -> extraer()) != null){
array_push($Categoriaes, new Categoria($resultado[0], $resultado[1], $resultado[2]));
}
return $Categoriaes;
}
}
?>
CategoriaDAO.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
class CategoriaDAO{
private $idCategoria;
private $nombre;
private $estado;
function CategoriaDAO ($pIdCategoria, $pNombre, $pEstado) {
$this -> idCategoria = $pIdCategoria;
$this -> nombre = $pNombre;
$this -> estado = $pEstado;
}
function consultar () {
return "select nombre, estado
from categoria
where idCategoria = '" . $this -> idCategoria . "'";
}
function crear () {
return "insert into categoria (nombre,estado)
values ('" . $this -> nombre . "', '" . $this -> estado . "')";
}
function consultarTodos () {
return "select idCategoria, nombre, estado
from Categoria";
}
function editar () {
return "update categoria
set nombre = '" . $this -> nombre . "'
where idCategoria = '" . $this -> idCategoria . "'";
}
function editarEstado () {
return "update categoria
set estado = '" . $this -> estado . "'
where idCategoria = '" . $this -> idCategoria . "'";
}
function consultarPorPagina ($cantidad, $pagina, $orden, $dir) {
if($orden == "" || $dir == ""){
return "select idCategoria, nombre, estado
from Categoria
limit " . strval(($pagina - 1) * $cantidad) . ", " . $cantidad;
}else{
return "select idCategoria, nombre, estado
from Categoria
order by " . $orden . " " . $dir . "
limit " . strval(($pagina - 1) * $cantidad) . ", " . $cantidad;
}
}
function consultarTotalRegistros () {
return "select count(idCategoria)
from Categoria";
}
function buscar($filtro){
return "select idCategoria, nombre, estado
from Categoria
where nombre like '" . $filtro . "%' or apellido like '" . $filtro . "%'";
}
}
?>
Valora esta pregunta


0