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

289
Visualizações
How can I convert string returned from API call to proper HTML in javascript?

I am calling an API command("@ReportProperty2(45899,exportdata,,'16115898')@") which returns HTML of the button but in string format and > and < are in &gt; and &lt; and there are double quotes are well which breaks my code at the following line:

const aaa = "@ReportProperty2(45899,exportdata,,'16115898')@";

RESULT FROM THE COMMAND:

"&lt;button type=button class=Button onclick="openwp('1677008','RHpdFBx7GS9YGFEwFmUUCyE4Ih8lHyA!H2JbUENBa1BV')" &gt;&lt;i class="fa fa-pencil-square-o" style="margin: 0 4px 0 0"&gt;&lt;/i&gt;Enter Budget&lt;/button&gt;"

I have tried replacing but it is throwing "unexpected token: identifier" error.

How can I convert the result to the following:

<button type="button" 
        class="Button" 
        onclick="openwp('1677008','RHpdFBx7GS9YGFEwFmUUCyE4Ih8lHyA!H2JbUENBa1BV')">
  <i class="fa fa-pencil-square-o" 
     style="margin: 0 4px 0 0" 
     data-original-title="" 
     title="">
  </i>
  Enter Budget
</button>

Please see pic for more info: enter image description here

I tried Lodash unescape,decodeHTMLEntities by Slavik Meltser, decodeEntities but it doesn't work.

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Depending on your template engine, there may be a more appropriate method, but assuming this @ output escapes as HTML, you can put it in an (non-rendered) HTML context:

<template id="aaa-html">@ReportProperty2(45899,exportdata,,'16115898')@</template>

Then you can select the element and read it from JavaScript:

const aaa = document.getElementById('aaa-html').innerHTML;
about 4 years ago · Santiago Gelvez 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