I cannot manipulate data coming from the Web Service (Json)

Asked

Viewed 53 times

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);?

  • key if using while/for/each ? and why not try inspecting your console to query is ease.

  • Tiago put there the code related to the insertion in the localstorage, and what goes wrong when it happens sff

  • I’ll upload a version to git, or js fiddle for you to check

No answers

Browser other questions tagged

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