-1
I have this script:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var txt = this.responseText;
var obj = JSON.parse(txt);
document.getElementById("demo").innerHTML = obj.value + ", " + obj.uri + " ... <br>";
}
};
xhttp.open("GET", "link?order=desc&cli=9999999999", true);
xhttp.send();
that returns me the content below.
{
"items": [{
"Value": 2149.44,
"boleto": {
"uri": "link.pdf",
"digits": "0000000000000000000000000000000000000",
"bank": "Boston Bank"
},
"doc": "999999-RNF",
"dueDate": "2018-10-11",
"cnpjCLI": "999999999999",
"cnpjREP": "999999999999"
}, {
"Value": 2149.44,
"boleto": {
"uri": "link.pdf",
"digits": "0000000000000000000000000000000000000",
"bank": "Boston Bank"
},
"doc": "999999-RNF",
"dueDate": "2018-10-11",
"cnpjCLI": "999999999999",
"cnpjREP": "999999999999"
} {
"Value": 2149.44,
"boleto": {
"uri": "link.pdf",
"digits": "0000000000000000000000000000000000000",
"bank": "Boston Bank"
},
"doc": "999999-RNF",
"dueDate": "2018-10-11",
"cnpjCLI": "999999999999",
"cnpjREP": "999999999999"
} {
"Value": 2149.44,
"boleto": {
"uri": "link.pdf",
"digits": "0000000000000000000000000000000000000",
"bank": "Boston Bank"
},
"doc": "999999-RNF",
"dueDate": "2018-10-11",
"cnpjCLI": "999999999999",
"cnpjREP": "999999999999"
} {
"Value": 2149.44,
"boleto": {
"uri": "link.pdf",
"digits": "0000000000000000000000000000000000000",
"bank": "Boston Bank"
},
"doc": "999999-RNF",
"dueDate": "2018-10-11",
"cnpjCLI": "999999999999",
"cnpjREP": "999999999999"
} {
"Value": 2149.44,
"boleto": {
"uri": "link.pdf",
"digits": "0000000000000000000000000000000000000",
"bank": "Boston Bank"
},
"doc": "999999-RNF",
"dueDate": "2018-10-11",
"cnpjCLI": "999999999999",
"cnpjREP": "999999999999"
}]
}
I need to print the items separately in HTML.
To separate, I’m trying something like the code below, but when I print with <div id='demo'></div>
, the answer is undefined, undefined
.
var txt = this.responseText;
var obj = JSON.parse(txt);
document.getElementById("demo").innerHTML = obj.value + ", " + obj.uri +" ... <br>";
You saw that your JSON has an attribute
items
what is an array? Tried to useobj.items[0].Value
?value
is different fromValue
. Something else,uri
is insideboleto
...– Rafael Tavares