Answer the question
In order to leave comments, you need to log in
Uncaught SyntaxError: Unexpected end of JSON input?
I process requests through ajax.
All requests are passed, except those that are processed by the database.
Previously, there was a file connection error, I coped with it. Now the error is "Unexpected end of JSON input".
js file
$( document ).ready(function() {
$("#do_signup").click(
function(){
sendAjaxForm('result_log', 'ajax_form', '../php_action/log.php');
//sendAjaxForm('result_pas', 'ajax_form', '../php_action/pas.php', 'in_2');
return false;
}
);
});
function sendAjaxForm(result_form, ajax_form, url) {
$.ajax({
url: url, //url страницы (action_ajax_form.php)
type: "POST", //метод отправки
dataType: "html", //формат данных
data: $("#"+ajax_form).serialize(), // Сеарилизуем объект
success: function(response) { //Данные отправлены успешно
result = $.parseJSON(response);//<------------ ЗДЕСЬ 35-ая строчка
$('#' + result_form).html(result.errors + "<script>border_mistake('in_1');</script>");
},
error: function(response) { // Данные не отправлены
$('#' + result_form).html('Ошибка. Данные не отправлены.');
}
});
}
<?php
require "../db.php";
$data = $_POST;
$errors = array();
if( trim($data['login']) == '' ):
$errors['errors'] = 'Введите логин' ;
elseif( R::count('users', 'login = ?', array($data['login'])) > 0 ):
$errors['errors'] = 'Пользователь с таким логином уже существует';
endif;
if (!empty($errors)){
echo json_encode($errors);
}
?>
Answer the question
In order to leave comments, you need to log in
According to the code, if the user exists - there will be an error, and there will be JSON with this error.
And if such a user does NOT exist, there will be an empty output, without any JSON at all, like you have in the second screenshot, right? So do something
else:
$errors['success']="Пользователь радостно создан. Аллилуя!";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question