Commit 67b256e0 by Patryk Czarnik

jQuery - pobieranie danych jednego produktu

parent 404360ac
...@@ -5,13 +5,39 @@ ...@@ -5,13 +5,39 @@
<title>Strona główna</title> <title>Strona główna</title>
<script th:src='@{/jquery-3.7.1.min.js}'></script> <script th:src='@{/jquery-3.7.1.min.js}'></script>
<script> <script>
function pobierz_dane(evt) {
// alert('Pobieram!');
let response = $.getJSON('products/1', null, (data) => {
console.log('data:', data);
$('#product').text('Nazwa produktu: ' + data.productName)
});
console.log(response);
}
$(document).ready(() => { $(document).ready(() => {
alert('Heja!'); // alert('Heja!');
$('#hello').html('To dopisało <b>jQuery</b>');
$('#btn-pobierz').on('click', pobierz_dane);
}); });
</script> </script>
<style>
#product {
margin: 2em;
border: 4px solid blue;
padding: 1em;
}
</style>
</head> </head>
<body> <body>
<h1>Witajcie w naszej apce</h1> <h1>Witajcie w naszej apce</h1>
<div id="hello"></div> <div id="hello"></div>
<div>
<button id="btn-pobierz">Pobierz dane</button>
</div>
<div id="product">
</div>
</body> </body>
</html> </html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment