I am using a for loop & jQuery output to html(). to output a JSON response to a html div.
In the for loop, I am transforming each result as follows into the output variable:
$.ajax(settings).done(function(response) {
var output = "";
for (i in response.Products) {
var productID = response.Products[i].ProductId;
var OtherVariables = response.Products[i].OtherResponseFields;
output += "<Some Other Code> <script type=\"application/javascript\"> ...some code unique to each productID... </script>";
}
$("#allResults").html(output);
});
The output works fine when I do not have the following in the output variable:
<script type=\"application/javascript\"> ...some code unique to each productID... </script>
But it breaks when I do add it as per the top code sample. I am looking at using the variable "clicks_productID" for the user to select a product quantity in a popup, before adding the product & qty to my database (not yet built).
Is there a better way of doing this (the results need to be different for each JSON return - which can be a variable response qty based on the submission)?
"<div class='uk-width-medium-1-4'> <div class='md-card'> <div class='md-card-head uk-text-center uk-position-relative'>....is not required for your question. Read How to Ask. Pay close attention to MCVE. Correct your question.