0
  • Node.js web server
  • Request handler in web server
app.get('/documents/:id.:format?', function(req, res) {
   **dataTobeSentToClientSideJavaScript** = processRequest (req);
   ... 
})
  • ajax request from client side javascript

    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?

gaurav jain
  • 1,267
  • 8
  • 20
  • 36

1 Answers1

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

Gal Ben-Haim
  • 17,433
  • 22
  • 78
  • 131