1
1
// Fetch product data from JSON source
2
2
// blocked by https://github.com/lightpanda-io/browsercore/issues/187
3
3
// window.addEventListener("load", () => {
4
+
5
+ // use XHR to retrieve the product's infos.
4
6
const detailsXHR = new XMLHttpRequest ( ) ;
5
7
// blocked by https://github.com/lightpanda-io/browsercore/issues/186
6
8
// detailsXHR.open('GET', 'json/product.json');
@@ -13,17 +15,19 @@ detailsXHR.open('GET', document.URL + 'json/product.json');
13
15
} ;
14
16
detailsXHR . send ( ) ;
15
17
16
- const reviewsXHR = new XMLHttpRequest ( ) ;
17
- // blocked by https://github.com/lightpanda-io/browsercore/issues/186
18
- // reviewsXHR.open('GET', 'json/reviews.json');
19
- reviewsXHR . open ( 'GET' , document . URL + 'json/reviews.json' ) ;
20
- reviewsXHR . responseType = 'json' ;
21
- reviewsXHR . onload = function ( ) {
22
- if ( this . status === 200 ) {
23
- updateReviews ( this . response ) ;
18
+ // use fetch to retrieve reviews.
19
+ ( async function ( ) {
20
+ try {
21
+ const url = document . URL + 'json/reviews.json' ;
22
+ const response = await fetch ( url ) ;
23
+ if ( ! response . ok ) {
24
+ throw new Error ( `Response status: ${ response . status } ` ) ;
25
+ }
26
+ updateReviews ( await response . json ( ) ) ;
27
+ } catch ( error ) {
28
+ console . error ( error . message ) ;
24
29
}
25
- } ;
26
- reviewsXHR . send ( ) ;
30
+ } ( ) ) ;
27
31
28
32
// blocked by https://github.com/lightpanda-io/browsercore/issues/185
29
33
//
0 commit comments