用于angularjs网站的带有json RPC的Node服务器

node server with json rpc for angularjs website

本文关键字:RPC Node 服务器 json angularjs 网站 用于      更新时间:2023-09-26

如何为节点和angularjs网站设置服务器json文件作为客户端?我的客户是一个用angularjs创建的网站。我如何设置这发送请求到服务器,并从那里得到响应?我的服务器是一个节点服务器。我如何设置json文件与我的客户端通信?

查看node-json-rpc.

你可以像这样在(节点)服务器端声明一个方法

server.addMethod('myMethod', function (params, callback) {
  var error, result;
  //implementation here
  callback(error, result);
});

,并在客户端(angular)像这样调用它:

client.call(
  {"method": "myMethod", "params": [1,2]},
  function (error, result) {
    //Handle result
  }
);