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

193
Vistas
Expected token-error when inserting a variable into a string - Javascript
   var value = liste[eigenschaft];
   document.getElementById("demo6").innerHTML = value;
   var data = '{"products":[{"ingramPartNumber":"7U0169"}, {"ingramPartNumber":"6XH440"}]}';

I made a successful request for an API from one of our online-distributors. In the var data (as shown above) I can list the name/value-pairs (f.E.: ingramPartNumber and the actual partNumber) and I get back the corresponding data.

However, we want to make the call a bit more dynamic. We implemented a search and we want to have the value of the search (in the example above the var value) as an actual value in var data.

However, if I substitute the product-number with the variable (as shown below), it throws an error (expected token identifier) .. What am I missing?

   var value = liste[eigenschaft];
   document.getElementById("demo6").innerHTML = value;
   var data = '{"products":[{"ingramPartNumber":"7U0169"}, {"ingramPartNumber":"'value'"}]}';
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are doing this

   var data = '{"products":[{"ingramPartNumber":"7U0169"}, {"ingramPartNumber":"'value'"}]}';

Where you should be using interpolation or concatenation

   var data = '{"products":[{"ingramPartNumber":"7U0169"}, {"ingramPartNumber":' + value + '}]}';
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