我有一个来自Model / registro.php的查询,它向我返回一个值Controllers / registro.php,我必须将数据返回给ajax,但不是。 什么可能是Controllers / registro.php的问题 没有返回任何成功的东西:function(data)ajax
型号/ registro.php
public function registrar($username,$email,$password,$confirm_password)
{
try{
$this->has= crypt($password);
$this->has_con= crypt($confirm_password);
$p= true;
$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();
}
}
控制器/ 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);
$respuesta="soy controllers";
$fail="segenero un erro";
//var_dump($t);
//echo ($t);
if($t == true){
//return "ok";
header('Content-Type: application/json');
echo json_encode($respuesta);
}else{
header('Content-Type: application/json');
echo json_encode($fail);
//echo "fail";
//echo json_encode("fail");
}
Ajax jquery
$('#register-submit').click(function(){
var data= $('#register-form').serialize();
$.ajax({
beforeSend:function(){
console.log(data);
},
type:'POST',
url:'../Controllers/registro.php',
data:data,
dataType:"json",
success: function(data){
console.log('nanananana');
console.log("soy data"+data);
}
});
});
答案 0 :(得分:1)
尝试使用xfa.host.print(1, "0", (xfa.host.numPages -1).toString(), 0, 0, 0, 0, 0);
e.preventDefault();
这里提到了相同的案例