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条回答 默认 最新

    报告相同问题?