Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

332
Visualizações
Typescript, pass arguments to Ejs page

I didn't set anything like the code below at first, just res.render('view', {prams}); I kept getting an error saying that the set header does not work.

"Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client"

Then, now that it is covered with the header below code, the related error has disappeared, but the ejs page is not receiving any parameters and <%=%> does not work. I'm not good at node js, so I'm actually using it as a clone. Could this possibly have something to do with cors? (I don't know what cors is well) Is there any way to send parameters here anyway?

            res.statusCode = 200;
            
            res.setHeader('Content-Type', 'text/plain');
            res.writeHead(200, {'Content-Type': 'application/xhtml+xml; charset=utf-8'});
            res.header({'Content-Type': 'application/xhtml+xml; charset=utf-8'});
            res.status(200).render("abcejs", {dataA, dataB});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are not defining data properly. I am assuming your data is defined as follows:

var dataA = somedataA;
var dataB = somedataB;

And you are passing them like this:

res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.writeHead(200, {'Content-Type': 'application/xhtml+xml; charset=utf-8'});
res.header({'Content-Type': 'application/xhtml+xml; charset=utf-8'});
res.status(200).render("abcejs", {dataA, dataB});

You should display data in following manner:

<%= dataA %>
<%= dataB %>

You can't print <%= data %> as you defined dataA and dataB. if you want to display parameters with different names then you have to define them while rendering like this:

 res.status(200).render("abcejs", {
  data1: dataA, 
  data2: dataB
 });

then you can display with <%= data1 %> <%= data2 %>

Learn more about ejs syntax: ejs.co

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda