【问题标题】:communication between express + angularJSexpress + angularJS之间的通信
【发布时间】:2013-02-15 20:03:56
【问题描述】:

使用 angularJS 我有一个数据文件,我可以在其中与数据库进行通信。

因此,我想将数据发送到我从前端获得的数据以将其发送到 Packend,但不知何故这现在正在工作。你能帮帮我吗?

app.get('/api/data/:id', function (req, res) {
    res.json({...});
});

app.post('/api/data/', function (req, res) {
    res.json({
        success: true
    })
});

对于 get 和 delete 函数,这很好用,但我不知道如何制作 post 和 put 函数以及如何在其中获取数据。

我在客户端上做什么

        add:function (data) {
            location = '/api/data/';
            $http.put(location, merchant, successCb).
                success(function(data, status, headers, config) {
                    console.log(arguments);
                    successCb(data);
                }).
                error(function(data, status, headers, config) {
                    console.log('Error:' + arguments);
                });
        },

有人可以帮我如何在服务器和客户端上编写它。 (我在客户端及其简单的 javascript 对象上获得了正确的数据。

【问题讨论】:

  • 您使用什么数据库系统?如果您向我们展示您在 get 中所做的事情,它也会有所帮助。例如,如果您想使用 MongoDB,可以阅读以下内容:pixelhandler.com/blog/2012/02/09/…

标签: javascript ajax node.js express angularjs


【解决方案1】:

您必须使用 $resource,这是与 RESTful 服务器端数据源通信的正确方式...

angularjs 在这里有关于 $resource 的很好的例子: http://docs.angularjs.org/api/ngResource.$resource

【讨论】:

    猜你喜欢
    • 2014-10-06
    • 1970-01-01
    • 1970-01-01
    • 2013-06-07
    • 1970-01-01
    • 1970-01-01
    • 2018-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多