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

196
Visualizações
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 Respostas
Responde à pergunta

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 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