I am trying to work with json and I almost have what I need. I get the correct information to display, but I need to pass each element of the array to a variable, and then print the variable. I would like to display all the elements in each array. The json data I work with is an invoice application ( www.curdbee.com ) and I am trying to show every invoice to a customer. The data I want to show is each position, the price of the position, and the total amount. Here is my code:
$(document).ready(function() { $.getJSON('https://nspirelab.curdbee.com/invoices.json?api_token=__token__', function(data){ $.each(data, function(index, item){ var total = item.invoice.total_billed; var lineItemName1 = item.invoice.line_items[0].name_and_description; var lineItemName2 = item.invoice.line_items[1].name_and_description; var lineItemPrice1 = item.invoice.line_items[0].price; var lineItemPrice2 = item.invoice.line_items[1].price; $('#results').append('<div class="lineItem"><ul><li>' + lineItemName1 + lineItemPrice1 + '</li><li>' + lineItemName2 + lineItemPrice2 + '</li><li>' + total + '</li></ul></div>'); }); }); });
user715564
source share