D
D
DaniilKhanin2017-09-02 19:04:58
JavaScript
DaniilKhanin, 2017-09-02 19:04:58

How to send two requests from one router?

setTimeout(()=> {
      console.log('setTimeout!');
      res.send('hello from setTimeout')
  },2000)
  
  res.send('hello');

how can i implement something like this?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
A
Alexander Aksentiev, 2017-09-02
@Sanasol

http doesn't work that way.
ajax/websocket

C
Coder321, 2017-09-02
@Coder321

Do res.write and catch via EventSource on the client

S
Serezha, 2017-09-02
Ahen @Ahen

https://socket.io

A
Abcdefgk, 2017-09-02
@Abcdefgk

Where are the two requests?

D
DaniilKhanin, 2017-09-02
@DaniilKhanin

the fact is that I want all rendering to be on the server side and not on the client, I want to make a request to another page to get the data and then send the ready html to the server, But I have a problem in the implementation of preloadera ... That is, i go to '/'
send ajax request to get data while request is being processed i show preloader on client like : once request is processed in cb function i get response, form html, and send to server... this is what i want.. .but I can't implement it because of two requests in the router '/' , ... the whole idea is to render on the server... yes, I probably will have to use websocket ..., just right now, many people write about rendering on the server side that it's fast .. . that's why it became so interesting to me res.send('preloaderOn');

A
Anton Sutarmin, 2017-09-04
@sutarmin

Judging by the task described in the comment, you need to manage the preloader on the client, not on the server. The process of getting data from the server should look something like this:
1. The user has performed an action that requires a request to the server (or the page has just loaded and needs more data to render).
2. The client (js) shows the user a preloader and sends a request to the server.
3. The server renders what it needs and sends the result to the client.
4. The client receives the rendered data, hides the preloader and shows the result.
If this is not your case, then try to describe your case point by point, focusing on each point on who is performing the action. For example:
1. User visits "/"
2.The client sends an ajax request to the server
3. The server responds
4. The client displays the result of the request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question