Делаю форму регистрации и столкнулся с проблемой.
ошибка: parsererror | SyntaxError: Unexpected end of JSON input
<form>
<h3>Email</h3>
<input id="email" class="empty" type="email" name="email" placeholder="example@example.com" value="<?php echo @$data['email']; ?>"><br>
<h3>Birthsday</h3>
<input id="birthsday" class="empty" type="text" name="birthsday" placeholder="dd/mm/yyyy" value="<?php echo @$data['birthsday']; ?>"><br>
<h3>Password</h3>
<input id="password" class="empty" type="password" name="password"><br>
<h3>Confirm Password</h3>
<input id="re_password" class="empty" type="password" name="re_password"><br>
<input class="submit" type="button" value="Register">
</form>
$('.submit').click(function () {
var error = $('form').find('.not_error');
if(error.length == 5) {
var userEmail = $.trim($('#email').val());
var userBirthsday = $('#birthsday').val();
var userPass = $('#password').val();
var userRePass = $('#re_password').val();
$.ajax({
type: 'POST',
url: 'reg.php',
dataType: 'json',
data: {user_Email: userEmail, user_birthsday: userBirthsday, user_pass: userPass, user_RePass: userRePass},
error: function(req, text, error) {
console.log('Ошибка AJAX: ' + text + ' | ' + error);
},
success: function (data) {
console.log('good');
}
});
} else {
ShowError();
}
});
require "db.php";
$data = $_POST;
if( isset($_POST['user_Email'], $_POST['user_birthsday'], $_POST['user_pass'], $_POST['user_RePass']) ) {
//reg
$errors = array();
if(trim($data['user_Email']) == '') {
$errors[] = 'Email';
}
$current_date = new \DateTime(date('d.m.Y'));
$date = new \DateTime($data['user_birthsday']);
if(trim($data['user_birthsday']) == '' || $date >= $current_date) {
$errors[] = '2';
}
if(($data['user_pass']) == '') {
$errors[] = '3';
}
if(($data['user_RePass']) != $data['user_pass']) {
$errors[] = '4';
}
if(empty ($errors)) {
$user = R::dispense('users');
$user->email = $data['user_Email'];
$user->birthsday = $data['user_birthsday'];
$user->password = $data['user_pass'];
R::store($user);
$text = '<div style="color:gren;">good</div><br />';
} else {
$text = '<div style="color:red;">'.array_shift($errors).'</div><br />';
}
}