How to make ajax request to mongodb

最后都变了- 提交于 2019-12-24 18:06:11

问题


I am building an app using Meteor. I am using the jquery datatables package - www.datatables.net to present my data/records. According to the documentation, I would connect the table to my MongoDB database by:

$('#example').DataTable( {
serverSide: true,
ajax: '/data-source'
});

The part I am unclear of is the 3rd line - Can someone help me understand how to make an ajax call to return data from my MongoDB database?? Here is more documentation on server-side processing for datatables:

https://datatables.net/manual/server-side

I have a collection named Products with the fields description, brand, price.


回答1:


<table id="example">
    <thead id="dataTable-header">
        <tr>
           <th>ID</th>
           <th>NAME</th>
        </tr> 
   </thead>
</table>

var dataTable = $('#example').DataTable({
                "orderable": false,
                'searching': true,
                "paging": true,
                language: {
                    processing: "<i class='fa fa-refresh fa-spin'></i>"
                 },
                "processing": true,
                "serverSide": true,
                "ajax": urlData,
                "columns":[
                    {
                        "orderable": false,
                        "class": "details-control",
                        "data": null,
                        "defaultContent": ""
                    },
                    {"orderable": false, "data": "name" }
                ],
                "columnDefs": [{    
                    "targets": 3,
                    "render": function (data, type, row) {
                        return '<a name="editAnchor" class="fa fa-ban"></a>';
                    },
                    "className": 'text-center'
                }]
            });

urlData is your json data with fields Id and Name.



来源:https://stackoverflow.com/questions/29761749/how-to-make-ajax-request-to-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!