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

223
Visualizações
javascript how to get the web page get Session variable

I'm trying to use a Session variable in javascript.

I have tried a number of post suggestions without success unfortinately.

I see this example all over the place.

    var userName = '<%= Session["UserName"] %>'

However that is not working, at least for me. What I am trying to do is as below.

    var qrdataString = "<qr-code data=" + "XL" + ' <%= Session["style"] %>'  + "></qr-code>";
    document.getElementById("styleqr").innerHTML = qrdataString; 

Using Single quotes where they appear above just returns the string as

    <%=Session["xUID"]%>   in the alert that I use to show me the returned value

Using Double quotes give me either - unexpected token: string literal - or unexpected token identifier.

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

After messing around for a while, and also stumbling on the following article, I have managed to get this going.

    https://newbedev.com/get-current-session-value-in-javascript 

FULL RESULT

HTML

    Dim xstyle: xstyle = session("style")

    <div class="hr">
      <input type="hidden" id="hdnSession" data-value= <%= xstyle %> />
    </div>

JAVASCRIPT

    var hdnString= $("#hdnSession").data('value');
    var qrdataString = "<qr-code data= " + hdnString  + " ></qr-code>";
    document.getElementById("qrcode").innerHTML = qrdataString;

HTML

    <div class="panel-body" id="qrcode">
        javasctipt inserts the html here  <!--qr-code data="test"></qr-code -->
    </div>
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