【问题标题】:returning data from server to an ajax request sent in client side javascript将数据从服务器返回到客户端 javascript 中发送的 ajax 请求
【发布时间】:2013-01-25 11:22:16
【问题描述】:
  • 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”对象?

【问题讨论】:

标签: node.js jquery client-side


【解决方案1】:

您想使用响应对象公开的方法,例如 res.write、res.end 或 res.json

看看http://nodejs.org/api/http.html#http_class_http_serverresponse (Node.js API)

因为您使用的是 Express - http://expressjs.com/api.html#res.status

【讨论】:

    猜你喜欢
    • 2013-08-13
    • 2015-05-23
    • 1970-01-01
    • 1970-01-01
    • 2013-04-11
    • 2021-12-07
    • 1970-01-01
    • 2015-11-11
    • 2018-01-12
    相关资源
    最近更新 更多