Opencart版本2.3.0.2,无法加载成功页面

Opencart版本2.3.0.2,无法加载成功页面,opencart,Opencart,我使用的是opencart 2.3.0.2最新版本,我在此创建了自定义支付模块,通过使用此模块,我无法加载成功页面。 下面是控制器文件 $response = $client->Operation($params); $response_value=$response->OperationResult->ResultData; $result_array=$response->OperationResult->ResultCode; $transation_num

我使用的是opencart 2.3.0.2最新版本,我在此创建了自定义支付模块,通过使用此模块,我无法加载成功页面。 下面是控制器文件

$response = $client->Operation($params);

$response_value=$response->OperationResult->ResultData;
$result_array=$response->OperationResult->ResultCode;
$transation_number=$response->OperationResult->TransactionNumber;
$xml_error=explode(":",$response->OperationResult->AdditionalInfo);

$json = array();
if(isset($xml_error['2'])){
    $payment_error=$xml_error['2'];
}else{
    $payment_error="";
}

if($payment_error == ''){

    $response_value = $response->OperationResult->ResultData;
    if($result_array == '0'){
        $report = "Transaction Id:".$transation_number;

        $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('config_order_status_id'),$report, false);
        $message = $response_value;

        $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('config_order_status_id'), $message, FALSE);

        $json['redirect'] = $this->url->link('checkout/success');

    }else{
        $json['error'] = $response_value;
    }
}else{
    $json['error'] = $payment_error;
}

$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
下面是我的ajax请求方法

$.ajax({ 
    type: 'post',
    data: $('#creditcard_payment input[type=\'radio\']:checked,#creditcard_payment input[type=\'text\'],#creditcard_payment input[type=\'checkbox\']:checked,#creditcard_payment input[type=\'hidden\'],#creditcard_payment select'),
    url: 'index.php?route=extension/payment/cnp/confirm',
    cache: false,
    beforeSend: function() {
        $('#button-confirm').button('loading');
    },
    complete: function() {
        $('#button-confirm').button('reset');
    },      
    success: function(json) {
        alert('test');
        if (json['error']) {
            alert(json['error']);
        }
        if (json['redirect']) {
            alert(json['redirect']);
            location = json['redirect'];
        }
    }
});
若您想要JSON响应,那个么将数据类型添加到AJAX选项中。如下

$.ajax{ url:'index.php?route=extension/payment/cnp/confirm', 数据类型:'JSON',//需要添加JSON响应。 键入:“post”, 数据:$'creditcard\u付款输入[类型=\'radio\']:选中,creditcard\u付款输入[类型=\'text\'],creditcard\u付款输入[类型=\'checkbox\']:选中,creditcard\u付款输入[类型=\'hidden\'],creditcard\u付款选择', cache:false, 发送前:函数{ $‘按钮确认’。按钮‘加载’; }, 完成:功能{ $‘按钮确认’。按钮‘重置’; }, 成功:functionjson{ 警报“测试”; 如果json['error']{ alertjson['error']; } 如果json['redirect']{ alertjson['redirect']; location=json['redirect']; } } }; 如果您直接使用JSON到ajax,那么就不要使用响应输出。这是因为许多模块根据需要使用此响应输出功能,如缩小、替换等

只需更换控制器的最后两行

$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));


也请告诉我们您的错误是什么,还可以从控制台检查是否得到正确的响应。我没有得到响应,控制台中的响应为空。ajax调用正在工作?是的,ajax调用也在工作,当我看到控制台日志时,响应页面在控制台中显示为html,只是无法重定向成功页面。请尝试使用window.location代替location
header('Content-Type: application/json');
echo json_encode($json);
die;