0

Пытаюсь отправить Ajax запрос на восстановления пароля.

В catalog/..../view/.../account/fotgotten.twig сделал кнопку <button type="button" id="forgot">send</button>

Тут же Ajax запрос

$(document).on('click', '#forgot', function(){
$.ajax({
url: 'index.php?route=account/forgotten/validate', //отправляем запрос в catalog/controller/account/forgotten.php ф-ию validate, которая protected function - может дело в protected?
type: 'post', //зщые
data: $('#ff input[type=\'text\']'),  //данные
dataType: 'json',  //json
success: function(json) {
if (json['redirect']) {
location = json['redirect']; //если все ок, то направим на страницу входа (или любую другую укажу)
} else if (json['error']) {
if (json['error']['warning']) { 
$.jGrowl(json['error']['warning']); //показ ошибок если есть, а она всего одна может быть - есть ли такой email или нет
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); // ну и Ajax ошбки запроса
}
});
});
});

catalog/controller/account/forgotten

ф-ия validate

protected function validate() {        
$json = array(); //создаю массив json        
    if (!isset($this->request->post['email'])) { //если нет данных
//          $this->error['warning'] = $this->language->get('error_email');  //закомментировал стандартный функционал
            $json['error']['warning'] = $this->language->get('error_email'); //то покажем ошибку
    } elseif (!$this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) { //проверка на существование среди email юзеров
            $json['error']['warning'] = $this->language->get('error_email'); // текст ошибки если если false
//          $this->error['warning'] = $this->language->get('error_email'); //закомментировал стандартный функционал
    }
    
    // Check if customer has been approved.
    $customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);

    if ($customer_info && !$customer_info['status']) {
            $json['error']['warning'] = $this->language->get('error_approved'); //отдаем текст ошибки
//          $this->error['warning'] = $this->language->get('error_approved'); //закомментировал стандартный функционал
    }
        
        $this->response->addHeader('Content-Type: application/json'); //json
    $this->response->setOutput(json_encode($json)); //json

//      return !$this->error; //закомментировал стандартный функционал
  }

по итогу при запросе получаю такую ошибку

Unrecognized token '<'
parsererror
<b>Warning</b>: call_user_func_array() expects parameter 1 to be a valid callback, cannot access protected method ControllerAccountForgotten::validate() in <b>/home/d/drobenfg/test.domrobensa.ru/storage/modification/system/engine/action.php</b> on line <b>79</b>

1 ответ 1

0

Замените protected function validate() на public function validate() .

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.