Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9270653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:25:24+00:00 2026-06-18T15:25:24+00:00

Node.js (express) web server Request handler in web server app.get(‘/documents/ajax/:id.:format?’, function(req, res) { console.log

  • 0
  • Node.js (express) web server
  • Request handler in web server
app.get('/documents/ajax/:id.:format?', function(req, res) {
   console.log ('Request Received');
   var body = 'hello world';
   res.writeHead(200, {
    'Content-Length': body.length,
    'Content-Type': 'text/plain'
   });

})
  • ajax request from client side javascript
  $.ajax({
    url : "/documents/ajax/" + item,
    success : function(msg) {
      alert ("success" + msg);
    },
    error : function(request, status, error) {
      alert("Error, returned: " + request);
      alert("Error, returned: " + status);
      alert("Error, returned: " + error);

    }
  });
  • I am able to receive the request on server side and I send 4 requests

But my success event is not getting called in client side JS. Also, when I stop my web server, then I see my error handlers get called.

Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:25:25+00:00Added an answer on June 18, 2026 at 3:25 pm

    The main issue is that you are not ending the response so the server never actually sends anything to the client. The server should respond with something like a file, a redirect, some text, etc. You need to finish the callback with a res.end, res.send, res.sendfile, res.redirect, res.render… See the docs.

    Furthermore, with express you want to use res.set to set the http headers:

    app.get('/documents/ajax/:id.:format?', function(req, res) {
       console.log ('Request Received');
       var body = 'hello world';
       res.set({'Content-Type': 'text/plain'});
       res.send(body);
    });
    

    200 is the default response code, so you don’t need to specify that and the length will be computed for you. These things are often easier to debug from the command line via curl:

    curl http://localhost:3000/documents/ajax/1
    

    and

    curl -I http://localhost:3000/documents/ajax/1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following express node.js app. It's using the 'redis' npm package. app.get(/test,function(req,res){
I have a JavaScript data structure like the following in my Node.js/Express web app:
Background I'm making a simple web server using express.js on top of node.js. When
I've got a simple web app running using Node and Express. I started writing
Intending to log use of the API (user/route/params/time) in a Heroku/Node/Express/Mongodb web app, to
I am writing a web app in node.js. Now every processing on the server
I'm trying to send the node instance JSON data using an ajax get request
I have been designing a web app in node.js with express and mongoDB, and
I've got a Node.js Express web app that is using the default port 3000
I create a web server with Node.js. I'm using the Express framework. The database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.