如何向mongodb发出ajax请求 [英] How to make ajax request to mongodb

查看:134
本文介绍了如何向mongodb发出ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Meteor构建应用程序。我正在使用jquery datatables包-www.datatables.net展示我的数据/记录。根据文档,我可以通过以下方式将表连接到我的MongoDB数据库:

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'
});

我不清楚的部分是第三行-有人可以帮助我了解如何制作Ajax调用以从我的MongoDB数据库返回数据?以下是有关数据表在服务器端处理的更多文档:

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

我有一个名为Products的集合,其中包含字段描述,品牌,价格。

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

推荐答案

<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是具有ID和Name字段的json数据。

urlData is your json data with fields Id and Name.

这篇关于如何向mongodb发出ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆