0
I’m trying to get the result of a request for an API (json), and send it to another function that will record to localstorage, I even got it with the product value, but with the name that is string is not working, I tried to give Trim(), substr() and nothing changes the value of the variable where the json data return is.
Code below:
function openModalquantidade(key){
$.getJSON("http://www.outletclube.com/web_api/products/", function(data) {
$('.modal').modal('show');
var imgWS = data.Products[key].Product.ProductImage[0].http;
var nomeWS = data.Products[key].Product.name;
nomeWS.toString();
nomeWS.substr(1, 5);
console.log(nomeWS);
var precoWS = data.Products[key].Product.promotional_price;
console.log(precoWS);
//var quantidadeWS = document.getElementById("quantidade").value;
var output2='<div class="add-product">';
output2+='<img src="' + imgWS + '" />';
output2+='<p class="nome">' + nomeWS + '</p>';
output2+='<p class="preco-antigo">' + precoWS + '</p>';
output2+='<p><input type= "text" id="quantidade" name="quantidade" class="form-control text-center" placeholder="Digite a quantidade"></p>';
output2+='<p><button type="button" class="btn btn-success" data-dismiss="modal" onclick="saveListWS(' + nomeWS +')">Comprar</button></p>';
output2+='</div>';
document.getElementById("modal-body").innerHTML = output2;
//$('.modal-body').html(output2);
});
}
What is the output of
console.log(nomeWS);
?– Jonatas Walker
key
if using while/for/each ? and why not try inspecting your console to query is ease.– KingRider
Tiago put there the code related to the insertion in the localstorage, and what goes wrong when it happens sff
– Miguel
I’ll upload a version to git, or js fiddle for you to check
– Tiago Marques