返回从服务器数据到客户端发送的Ajax请求的JavaScript
问题描述:
- Node.js的web服务器 在web服务器从
app.get('/documents/:id.:format?', function(req, res) { **dataTobeSentToClientSideJavaScript** = processRequest (req); ... })
- 请求处理机客户端javascript
var request = $.ajax({ url: "/documents/xxx", }); request.done(handleResponse);
我能够获得服务器端请求
应在服务器端写什么代码,这样我可以填充预计将在我的Ajax请求上面的“handleRespone”对象dataTobeSentToClientSideJavaScript在服务器端创建?
答
您希望使用的响应对象公开,如res.write,res.end或res.json
看看http://nodejs.org/api/http.html#http_class_http_serverresponse (Node.js的API)
因为你方法'使用快递 - http://expressjs.com/api.html#res.status
它有助于:http://*.com/questions/6011984/basic-ajax-send-receive-with-node-js – 2013-02-10 20:34:53