Javascript 数据表的Json对象数组

Javascript 数据表的Json对象数组,javascript,php,html,json,Javascript,Php,Html,Json,我有一个php fileads.php,它返回由一组记录组成的json对象数组 阵列是 [{"hea":{"0":"Kidney Stone Removal"},"id":{"0":"16282238572"},"desc":{"0":"Get treated at top kidney center"},"desc2":{"0":"Take a free advice from our experts"},"url":{"0":"www.ainuindia.com"},"cli":{"0":"

我有一个php fileads.php,它返回由一组记录组成的json对象数组

阵列是

[{"hea":{"0":"Kidney Stone Removal"},"id":{"0":"16282238572"},"desc":{"0":"Get treated at top kidney center"},"desc2":{"0":"Take a free advice from our experts"},"url":{"0":"www.ainuindia.com"},"cli":{"0":"1"},"cpc":{"0":"0"},"con":{"0":"0"},"cost":null,"ctr":{"0":"5.26%"},"imp":{"0":"19"},"ap":{"0":"2.2"}}]
我的JavaSRcript是

$("#example1").dataTable();
            $("#groupid").change(function(){
            var oTable = $('#example1').dataTable();
            var grpvalue=$('#groupid').val();
                            $.ajax({
                            type:"post", 
                            dataType : 'json',
                            url:"pages/ads.php", 
                            data:"adgroup="+grpvalue, 
                            success: function(s) {
                            oTable.fnClearTable();
                            for(var i = 0; i < s.length; i++) {
                                oTable.fnAddData([          
                                    s[i]['hea'],
                                    s[i]['id'],
                                    s[i]['desc'],
                                    s[i]['desc2'],
                                    s[i]['url'],
                                    s[i]['cli'],
                                    s[i]['cpc'],
                                    s[i]['con'],
                                    s[i]['cost'],
                                    s[i]['ctr'],
                                    s[i]['imp'],
                                    s[i]['ap']

                                    ]);
                                    }
                                    }
                        });


            });
Html数据表是

<table id="example1" class="table table-bordered table-striped num-right-alignct">
                                        <thead>

                                            <tr>
                                                <th  style="text-align: center;">Ad Headline</th>
                                                <th  style="text-align: center;">Ad ID</th>
                                                <th  style="text-align: center;">Ad Description 1</th>
                                                <th  style="text-align: center;">Ad Description 2</th>
                                                <th  style="text-align: center;">URL Appeared</th>
                                                <th  style="text-align: center;">Clicks</th>
                                                <th  style="text-align: center;">CPC</th>
                                                <th  style="text-align: center;">Conversions</th>
                                                <th  style="text-align: center;">CTR %</th>
                                                <th  style="text-align: center;">Impressions</th>
                                                <th  style="text-align: center;">Avg Pos</th>


                                            </tr>
                                        </thead>

                                        <tbody>



                                        </tbody>


                                    </table>

当我检索这些值时,整个数据只嵌入到第一列而不是其他列中,如何在所有列和行都已填充的情况下将这些值放入数据表中?

请尝试下面的代码。希望这对你有帮助

 $("#example1").dataTable();
                $("#groupid").change(function(){
                var oTable = $('#example1').dataTable();
                var grpvalue=$('#groupid').val();
                var col = ["hea", "id", "desc", "desc", "desc2", "url", "cli","cpc","con","cost","ctr","imp","ap"]; 
                                $.ajax({
                                type:"post", 
                                dataType : 'json',
                                url:"pages/ads.php", 
                                data:"adgroup="+grpvalue, 
                                success: function(s) {
                                oTable.fnClearTable();
                                for(var i = 0; i < s.length; i++) {
                                 $("#example1 tr:first td:nth-child("+i+")" ).html(s[i][col[i]]);
                                        }
                                        }
                            });


                });