weixin_33704591 2016-06-30 15:32 采纳率: 0%
浏览 32

使用ajax返回php数组

I am trying to fill a html table with an array. The function is in php and when I call it, without ajax, but just with php it works fine but as soon as I try calling it using ajax, it returns an empty array

        function getAJAX(){
        var token = window.token;
        $.ajax({ url: 'functions.php',
                 data: {action: 'openSales', access: token}
                 type: 'post',
                 success: function(output) {
                              document.getElementById('OpenSales').innerHTML = '';
                             var output = jQuery.parseJSON(output);
                              makeTable($('#OpenSales'),output,'overdueSales');
                          }
        }); 
    }

The makeTable function does work when called outside the ajax function so that is not the problem, the php code is

        if(isset($_POST['action']) && !empty($_POST['action'])) {
        $action = $_POST['action'];
        $token = $_POST['access'];
        switch($action) {
            case 'openSales' : echo json_encode(getOverdueSales($token)); break;
            case 'blah' : blah();break;
        }
    }

Anyone see what I am doing wrong here?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改
    • ¥20 wireshark抓不到vlan
    • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
    • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持