I tell you my problem I'm trying to edit a record and the data I send to call through an id with Js and it works.
But after sending that id with Ajax through "POST"
to a method to do the query and return the values, it sends me an error in the method, and the error is in "if"
but I still do not understand why.
And by the way, when sending the data by ajax, I had dataType:"json"
but I commented it because it did not show me anything.
I leave the code so you can help me ...
users.js (Js and Ajax):
$(document).on("click", ".btnEditarUsuario", function(){
var idUsuario = $(this).attr("idUsuario");
console.log("idUsuario", idUsuario); //Mandando llamar el id con la consola
//AJAX
var datos = new FormData();
datos.append("idUsuario", idUsuario);
$.ajax({
url:"../ajax/usuarios.ajax.php",
method: "POST",
data: datos,
cache: false,
contentType: false,
processData: false,
//dataType: "json",
success: function(respuesta){
console.log("respuesta", respuesta);
}
}); })
And finally in the if at the end is where is the supposed error that appears in the console, only what I do is through the method to consult the data with the id that I send from the post of Ajax and here execute it.
require_once "../controladores/usuarios.controlador.php";
require_once "../modelos/usuarios.modelo.php";
class AjaxUsuarios{
/*=============================================
EDITAR USUARIO
=============================================*/
public $idUsuario;
public function ajaxEditarUsuario(){
$item = "idusuario";
$valor = $this->idUsuario;
$respuesta = ControladorUsuarios::ctrMostrarUsuarios($item, $valor);
echo json_encode($respuesta);
}//Cierra funcion
}//Cierra clase
// EDITAR USUARIO AQUI ES EL ERROR
if(isset($_POST["idUsuario"])){
$editar = new AjaxUsuarios();
$editar -> idUsuario = $_POST["idUsuario"];
$editar -> ajaxEditarUsuario();
}
This is the class I'm calling with the HTML:
<div class="btn-group">
<button class="btn btn-warning btnEditarUsuario"
idUsuario="'.$value["idusuario"].'" data-toggle="modal"
data-target="#modalEditarUsuario"><i class="fa fa-pencil"></i></button>
<button class="btn btn-danger"><i class="fa fa-times"></i></button>
</div>
What now shows me in console are the data I need highlighted in red, the rest is HTML:
RESOLVED UPDATE
Console, the data I expected to obtain:
Class: