douzhi7070 2014-04-03 14:15
浏览 30
已采纳

AJAX / json返回null打开购物车

Hi Im attempting a simple ajax request but I keep getting a null value for json.

Here is my javascript...

<script>
$(document).ready( function() { 
$('#donate-box-submit').on('click', function() {

    var donate_code = $('#charity-campaign-code').val();
    var donate_amount = $('#charity-campaign-amount').val();
    $.ajax({
        url: 'index.php?route=donate/donatenow',
        type: 'post',
        data: {
            donate_code: donate_code,
            donate_amount: donate_amount
        },
        dataType: 'json',
        beforeSend: function() {

        },  
        complete: function() {

        },          
        success: function(json) {
        console.log(json);
            alert(json['test']);
        },
        error: function() {
        }
    });
   });

 });



</script>

and my php...

    public function donatenow() {

    $json = array(
    'test' => 'Output this text'        
    );


    $this->response->setOutput(json_encode($json));     
}

I have also tried echo json_encode($json); just to rule out any issues with that OpenCart function, but the same issue is still there.

  • 写回答

1条回答 默认 最新

  • dongweihuai5601 2014-04-03 14:49
    关注

    The problem is the route you are using to call the method. Not sure on exactly what class you are using as the controller, but there should be three parts to the route: route=aaa/bbb/donatenow where as you've got aaa/donatenow

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题