Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

221
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda