Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230928
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
javab_20230928
Commits
96f1f346
Commit
96f1f346
authored
Nov 10, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Obsługa parametru z id produktu
parent
b770aa00
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
14 deletions
+24
-14
index.html
PC38-RestSpring/src/main/resources/templates/index.html
+24
-14
No files found.
PC38-RestSpring/src/main/resources/templates/index.html
View file @
96f1f346
...
...
@@ -6,25 +6,33 @@
<script
th:src=
'@{/jquery-3.7.1.min.js}'
></script>
<script>
function
pobierz_dane
(
evt
)
{
evt
.
preventDefault
();
let
productId
=
$
(
'#productId'
).
val
();
console
.
log
(
'pid:'
,
productId
);
if
(
productId
)
{
let
adres
=
'products/'
+
productId
;
console
.
log
(
'adres:'
,
adres
);
// alert('Pobieram!');
let
response
=
$
.
getJSON
(
'products/1'
,
null
,
(
data
)
=>
{
// console.log('data:', data);
let
html
=
`<table>
<tr><th>id</th><td>
${
data
.
productId
}
</td></tr>
<tr><th>Nazwa</th><td>
${
data
.
productName
}
</td></tr>
<tr><th>Cena</th><td>
${
data
.
price
}
</td></tr>
<tr><th>Opis</th><td>
${
data
.
description
}
</td></tr>
</table>`
;
// $('#product').text('Nazwa produktu: ' + data.productName)
$
(
'#product'
).
html
(
html
);
});
console
.
log
(
response
);
let
response
=
$
.
getJSON
(
adres
,
null
,
(
data
)
=>
{
// console.log('data:', data);
let
html
=
`<table>
<tr><th>id</th><td>
${
data
.
productId
}
</td></tr>
<tr><th>Nazwa</th><td>
${
data
.
productName
}
</td></tr>
<tr><th>Cena</th><td>
${
data
.
price
}
</td></tr>
<tr><th>Opis</th><td>
${
data
.
description
}
</td></tr>
</table>`
;
// $('#product').text('Nazwa produktu: ' + data.productName)
$
(
'#product'
).
html
(
html
);
});
console
.
log
(
response
);
}
}
$
(
document
).
ready
(()
=>
{
// alert('Heja!');
$
(
'#hello'
).
html
(
'To dopisało <b>jQuery</b>'
);
$
(
'#btn-pobierz'
).
on
(
'click'
,
pobierz_dane
);
$
(
'#productId'
).
on
(
'change'
,
pobierz_dane
);
});
</script>
<style>
...
...
@@ -48,9 +56,11 @@
<body>
<h1>
Witajcie w naszej apce
</h1>
<div
id=
"hello"
></div>
<div>
<form
id=
"product-form"
>
<input
type=
"number"
id=
"productId"
>
<button
id=
"btn-pobierz"
>
Pobierz dane
</button>
</
div
>
</
form
>
<div
id=
"product"
>
</div>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment