Skip to content
Snippets Groups Projects
Commit 1358b30c authored by dnsadmin's avatar dnsadmin
Browse files

3. Feladat

parent 99278112
Branches
No related tags found
No related merge requests found
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AJAX demo</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
</head>
<body>
<script type="text/javascript">
if (location.protocol == "file:") {
document.write("<div style='background: #f00; color: #fff; " +
"padding: 16px; font-weight: bold; text-align: center;'>" +
"You've opened this file from your local hard drive. " +
"You won't be able to call your services this way.<br />" +
"Open this file from <code>http://localhost:XXXXX/static/" +
location.href.split("/").pop() + "</code> where <code>XXXXX</code> is " +
"your own port printed by Flask on the console.</div>");
}
function button_click_handler(evt) {
var button = evt.target;
alert("rendszam = " + button.name);
}
function load_data_into_table(data) {
var jarmuvek = data.jarmuvek;
var table = document.getElementById("jarmuvek");
for (var i = 0; i < jarmuvek.length; i++) {
var vehicle = jarmuvek[i];
/* insert row and cells on last position (-1)
https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement.insertRow */
var row = table.insertRow(-1);
var cell_jarmu_kulcs = row.insertCell(-1);
var cell_rsz = row.insertCell(-1);
var cell_uh = row.insertCell(-1);
var cell_btn = row.insertCell(-1);
/* $(element) makes it possible to call jQuery
convenience methods on them like text() */
$(cell_jarmu_kulcs).text(vehicle.jarmu_kulcs);
$(cell_rsz).text(vehicle.rendszam);
$(cell_uh).text(vehicle.uzembehelyezes);
var button = document.createElement("input");
button.setAttribute("type", "button");
button.setAttribute("value", ">");
button.setAttribute("name", vehicle.rendszam);
cell_btn.appendChild(button);
$(button).click(button_click_handler);
}
}
$(function() {
$.ajax({
url: "../jarmuvek.json",
dataType: "json",
success: load_data_into_table
});
});
</script>
<table id="jarmuvek">
<tr>
<th>jarmu_kulcs</th>
<th>rendszam</th>
<th>uzembehelyezes</th>
</tr>
</table>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment