-1

I'ld like to send two successive ejs page to the client using the following code:

app.post('/', function(req,res) {
  res.render('yourDemandIsBeingProceed.ejs');
  //some code which require time (open an external programm, run a script, edit a response)
  res.render('hereIsYourResult.ejs');
  res.end();
});

So, once once the client post his form, he receives a page asking him to wait for a few seconds and then the page containing the response is send.

any suggestion?

many thx

4
  • I forgot ot mention that i'ld like to avoid using socket.io Commented Mar 2, 2017 at 12:38
  • This is not how http works. Once you execute res.render the connection is closed and you cannot send any more data to the client. Commented Mar 2, 2017 at 12:43
  • If you use pug, take a look my answer Commented Oct 9, 2017 at 10:25
  • Possible duplicate of How to render multiple views using Node+Express Commented Oct 9, 2017 at 10:26

2 Answers 2

0

What you can do is have client-side code in yourDemandIsBeingProceed.ejs when the page loads that performs a get/post request to a different endpoint. When the result from that is received, hide/show different elements inside yourDemandIsBeingProceed.ejs so it looks more like hereIsYourResult.ejs

Sign up to request clarification or add additional context in comments.

Comments

0

What you really should do is have the user submit information via front end AJAX and put up a loading graphic until the JSON response gets back. AJAX was developed for situations exactly like this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.