@aftemaht

Почему возникает ошибка Unexpected token in JSON at position 0 parsererror?

При оформлении заказа и выбора способа оплаты при доставке, появляется такая ошибка.
Ошибка
60d5bcc8e57bb143998370.png

Скорее всего проблема возникает в этом участке кода
js
$('body').on('click', '#go_out', function(){

        var type_pay = $('#go_out').data('pay');
        $.post('/index.php?route=checkout/payment_method/save', {'payment_method' : type_pay, 'agree': 1, 'comment': ''}, function(){

        });
        $.get('/index.php?route=checkout/confirm', function(data){

            $('#user_confirm').html(data);
            // Если оплата при получении
            if(type_pay == 'cod'){
                $.ajax({
                    url: 'index.php?route=extension/payment/cod/confirm',
                    dataType: 'json',
                    beforeSend: function() {
                        $('#button-confirm').button('loading');
                    },
                    complete: function() {
                        $('#button-confirm').button('reset');
                    },
                    success: function(json) {
                        if (json['redirect']) {
                            location = json['redirect'];
                        }
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
            }
            // Если оплата онлайн
            if(type_pay == 'anyway'){
                $('#user_confirm form .buttons .pull-right input').click();
            }

        });
    });

Прикрепляю также код из файла cod.php
cod.php
<?php
class ControllerExtensionPaymentCod extends Controller {
	public function index() {
		return $this->load->view('extension/payment/cod');
	}

	public function confirm() {
		$json = array();
		
		if ($this->session->data['payment_method']['code'] == 'cod') {
			$this->load->model('checkout/order');

			$this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('payment_cod_order_status_id'));
		
			$json['redirect'] = $this->url->link('checkout/success');
		}
		
		$this->response->addHeader('Content-Type: application/json');
		$this->response->setOutput(json_encode($json));		
	}
}
  • Вопрос задан
  • 132 просмотра
Решения вопроса 1
@galaxy
Из-за Notice у тебя ошибка. Не выводи ошибки PHP в браузер (display_errors = Off) для начала. И разберись с нотисом, почему в сессии не оказалось payment_method
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы