[英]returning data from server to an ajax request sent in client side javascript
app.get('/documents/:id.:format?', function(req, res) { **dataTobeSentToClientSideJavaScript** = processRequest (req); ... })
ajax request from client side javascript 来自客户端javascript的ajax请求
var request = $.ajax({ url: "/documents/xxx", }); request.done(handleResponse);
I am able to receive the request on server side 我可以在服务器端收到请求
What code should be written on server side so that I can populate the "handleRespone" object expected in my ajax request above with dataTobeSentToClientSideJavaScript created on server side? 应该在服务器端编写什么代码,以便可以使用在服务器端创建的dataTobeSentToClientSideJavaScript填充上述ajax请求中期望的“ handleRespone”对象?
You want to use methods exposed by the response object such as res.write, res.end or res.json 您想使用响应对象公开的方法,例如res.write,res.end或res.json
take a look at http://nodejs.org/api/http.html#http_class_http_serverresponse (Node.js API) 看看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 并且由于您使用的是Express- http://expressjs.com/api.html#res.status
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.