I'm learning how to get JSON data into a table. My table:
<html>
<head>
<title>V.0.0.31</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
$(function() {
var people = [];
$.getJSON(("http://my address:3000/m_info/", { mode: 'no-cors'}), function(data) {
$.each(data, function(i, f) {
var tblRow = "<tr>" + "<td>" + f.n_m + "</td>" +
"<td>" + f.name_m + "</td>" + "<td>" + f.address + "</td>" + "<td>" + f.full_name_of_direcor + "</td>" + "<td>" + f.phone_number + "</td>" + "</tr>"
$(tblRow).appendTo("#userdata tbody");
});
});
});
</script>
</head>
<body>
<div class="wrapper">
<div class="profile">
<table id= "userdata" border="2">
<thead>
<th>Number mine</th>
<th>Name mine</th>
<th>Adress</th>
<th>Full name of the director</th>
<th>Phone number</th>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</body>
</html>
Just in case, I'll indicate how I get JSON data.
const Pool = require('pg').Pool
const pool = new Pool({
user: '',
host: 'address',
database: '',
password: '',
port: 5432,
})
const getMinfo = (request, response) => {
pool.query('SELECT * FROM mine_info', (error, results) => {
if (error) {
throw error
}
response.status(200).json(results.rows)
})
}
const createRow = (request, response) => {
const { n_mine, name_mine, adress, full_name_of_direcor, phone_number } = request.body
pool.query('INSERT INTO mine_info (n_m, name_m, address, full_name_of_direcor, phone_number) VALUES ($1, $2, $3, $4, $5) RETURNING *', [n_m, name_m, address, full_name_of_direcor, phone_number], (error, results) => {
if (error) {
throw error
}
response.status(201).send(`User added with ID: ${results.rows[0].id}`)
})
}
module.exports = {
getMinfo,
createRow,
}
I can also state with accuracy that the JSON data is available at this link
But I get an error as if I'm following a completely different link enter image description here
I tried to change the link, which didn't help. I also did a local JSON file to check whether it takes data in principle.