简体   繁体   English

express + angularJS之间的通信

[英]communication between express + angularJS

with angularJS i have got a datafile, where i communicate with the database. 与angularJS我有一个数据文件,我在其中与数据库进行通信。

Therefore i want to send the data to the i got from the frontend to send it to the packend, but somehow this is now working. 因此,我想将数据发送到我从前端获得的数据,再将其发送到Packend,但是现在某种程度上,这是可行的。 can you please help me. 你能帮我么。

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

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

for the get and delete functions this works fine, but I have no idea how to make the post and put function and how to get the data in there. 对于get和delete函数,这很好用,但是我不知道如何制作post和put函数以及如何在其中获取数据。

Here what i do on the client 这是我对客户的处理

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

can someone please help me how to write that on the server and client. 有人可以帮我如何在服务器和客户端上编写该代码吗? (i get the right data on the client and its a simple javascript object. (我在客户端及其简单的javascript对象上获取了正确的数据。

you must use $resource which is the correct way for communicating with restful server side data source... 您必须使用$ resource,这是与静态服务器端数据源进行通信的正确方法...

angularjs has very nice examples about $resource here: http://docs.angularjs.org/api/ngResource .$resource angularjs在这里有关于$ resource的非常好的示例: http ://docs.angularjs.org/api/ngResource。$ resource

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM