Answer the question
In order to leave comments, you need to log in
Why does Unexpected token in JSON at position 0 parsererror occur?
When placing an order and choosing a payment method on delivery, the following error appears.
$('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();
}
});
});
<?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));
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question