Answer the question
In order to leave comments, you need to log in
How to output json?
There are json files with data of the form
{
"page": "3",
"total": "26",
"records": "75247",
"rows": [
{
"id": "af9b185bdc84499fab5258bdb698a305",
"tenderID": "UA-2017-02-17-002412-c",
"title": "Конструкційні вироби",
"status": "active.auction",
"dateModified": "2017-03-06T09:33:45.641137+02:00"
}
]
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>JSON</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<script type="application/javascript">
$(function() {
var url = "http://localhost/123/1.json";
$.getJSON(url, function(data) {
displayResults(data.rows);
});
function displayResults(jsonResults) {
for (i = 0; i < jsonResults.length; i++) {
pageHtmlString += ('' + jsonResults[i].tenderID + '');
}
}
});
</script>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
function displayResults(jsonResults) {
const body = document.querySelector('body');
const resultString = jsonResults.reduce((string, row) => string + `${row.tenderID} `, '');
body.innerText = resultString;
}
A variable pageHtmlString
is taken from nowhere and goes nowhere.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question