I have a problem returning a data from Controllers/registro
in php
to% Ajax
. The controller receives a data from Model/registro.php
, but it does not return the Ajax
that data it receives.
What could be the reason why Controller/registro.php
does not return any data to Ajax
, even though it does insert in Model/registro.php
?
Model / registro.php
public function registrar($username, $email, $password, $confirm_password)
{
try
{
$this->has = crypt($password);
$this->has_con = crypt($confirm_password);
$p= "soy diferente de uno";
$registro = $this->conexion->conexion->query("insert into registro_por (nombre, correo, pass, conf_pass) values( '$username', '$email', '$this->has', '$this->has_con')");
if ($registro)
{
return $p;
}
else
{
throw new Exception("Fallos la ejecución");
}
}
catch (Exception $e)
{
echo 'Message: '.$e->getMessage();
}
}
Controllers / registro.php
require_once("../Model/registro.php");
$username = $_POST["username"];
$email = $_POST["email"];
$password = $_POST["password"];
$confirm_password = $_POST["confirm_password"];
$reg = new Registro();
$t = $reg->registrar($username, $email, $password, $confirm_password);
var_dump($t);
if ($t != 1)
{
//return "ok";
//echo "es difenrete de uno";
return $t;
}
else
{
return $t;
//echo "fail";
}
JavaScript
Ajax
jQuery
receives the data from the controller:
$('#register-submit').click(function () {
var data = $('#register-form').serialize();
$.ajax({
beforeSend: function () {
console.log(data);
},
type: 'POST',
url: '../Controllers/registro.php',
data: data,
success: function (data) {
console.log('nanananana');
console.log("soy data"+data);
}
});
});