Error in Javascript array

Asked

Viewed 47 times

0

Hello, I’m putting a script from Zanox on my site to retarget products in an e-commerce.

When I put the script to pull isolated variables everything works, but when I need to pull the variables inside an array, it doesn’t work.

Follow the script that’s right:

<script type="text/javascript">
var zx_identifier = "<%=RSProdutoDetalhe("Codigo")%>",
var zx_fn = "<%=RSProdutoDetalhe("Nome")%>",
var zx_category = "<%=RSProdutoDetalhe("Categoria")%>"
</script>

Follow the script that is wrong:

<script type="text/javascript">
var zx_products = [{
"zx_identifier" : "<%=RSProdutoDetalhe("Codigo")%>",
"zx_amount" : "<%=PrecoProdutoCarrinho%>",
"zx_currency" : "BRL",
"zx_quantity" : "<%=RSPedidoTempGrade("Quantidade")%>"
}];
</script>

Then you would need to make a loop to pick up any products from the page within that array

Can someone help me? Thank you

  • Which error is generated?

  • ¿it would not have to be "zx_amount":"<%=Precoproductocarrinho("Preco")%>"

  • The language used among the tokens <%= and %> is PHP or something? I don’t know this Zanox...

1 answer

0

Use JSON.stringify, below:

var zx_products = JSON.stringify({
"zx_identifier" : "<%=RSProdutoDetalhe("Codigo")%>",
"zx_amount" : "<%=PrecoProdutoCarrinho%>",
"zx_currency" : "BRL",
"zx_quantity" : "<%=RSPedidoTempGrade("Quantidade")%>"
});

More details: https://www.w3schools.com/js/js_json_stringify.asp

Browser other questions tagged

You are not signed in. Login or sign up in order to post.