Answer the question
In order to leave comments, you need to log in
Not sending data via ajax to kohana?
Hello. I'm doing a small service, it works on kohane, ajax.
Doesn't want to write data via ajax, 500 (Internal Server Error) I don't understand what the error is.
Here is the controller code that receives the data
$data = array();
$auth = Auth::instance();
$phone = Arr::get($_POST, 'phone', '');
$password = Arr::get($_POST, 'password', '');
$name = Arr::get($_POST, 'username', '');
$email = Arr::get($_POST, 'email', '');
$passwordHash = $auth->hash_password($password);
$registration = new Model_Register();
$res = $registration->reg($email, $name, $phone, $passwordHash);
echo json_encode($data['result'] => $res));
public function reg($email, $name, $phone, $passwordHash)
{
$user = new Model_User();
$user->email = $email;
$user->username = $name;
$user->phone = $phone;
$user->password = $passwordHash;
$user->save();
return true;
}
$.ajax({
type:'POST',
url:'/reg/',
dataType:'json',
data:{
phone:phone,
password:pass,
username:name,
email:email
},
success:function(data){
if(data == 'ok'){
alert('все ок');
}else{
alert('ошибка');
}
},
error:function(data){
alert(data);
}
});
Answer the question
In order to leave comments, you need to log in
Why at all?
And in the second, when adding a user, there is no need to hash the password, the rules are set in the model - when you specify the field with the password, it will hash itself.
Therefore enough
$user = new Model_User();
$user->email = $email;
$user->username = $name;
$user->phone = $phone;
$user->password = $password;
$user->save();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question