0
  • Node.js 网络服务器
  • Web 服务器中的请求处理程序
app.get('/documents/:id.:format?', function(req, res) {
   **dataTobeSentToClientSideJavaScript** = processRequest (req);
   ... 
})
  • 来自客户端javascript的ajax请求

    var request = $.ajax({
    url: "/documents/xxx",
    });
    request.done(handleResponse);
    
  • 我能够在服务器端接收请求

应该在服务器端编写什么代码,以便我可以使用在服务器端创建的 dataTobeSentToClientSideJavaScript 填充上面的 ajax 请求中预期的“handleRespone”对象?

4

1 回答 1

1

You want to use methods exposed by the response object such as res.write, res.end or res.json

take a look at http://nodejs.org/api/http.html#http_class_http_serverresponse (Node.js API)

and since you're using Express - http://expressjs.com/api.html#res.status

于 2013-02-10T13:56:47.220 回答