File tree Expand file tree Collapse file tree 1 file changed +13
-16
lines changed
Expand file tree Collapse file tree 1 file changed +13
-16
lines changed Original file line number Diff line number Diff line change 1- function includeHTML ( ) {
2- const z = document . getElementsByTagName ( "*" ) ;
3- for ( let i = 0 ; i < z . length ; i ++ ) {
4- const elmnt = z [ i ] ;
5- const file = elmnt . getAttribute ( "inc" ) ;
6- if ( file ) {
7- const xhttp = new XMLHttpRequest ( ) ;
8- xhttp . onreadystatechange = function ( ) {
9- if ( this . readyState == 4 ) {
10- if ( this . status == 200 ) { elmnt . innerHTML = this . responseText ; }
11- elmnt . removeAttribute ( "inc" ) ;
12- } }
13- xhttp . open ( "GET" , file , true ) ;
14- xhttp . send ( ) ;
15- return ;
1+ async function includeHTML ( ) {
2+ const z = document . querySelectorAll ( '[inc]' ) ;
3+ for ( const elmnt of z ) {
4+ const file = elmnt . getAttribute ( 'inc' ) ;
5+ try {
6+ const response = await fetch ( file ) ;
7+ if ( response . ok ) {
8+ elmnt . innerHTML = await response . text ( ) ;
9+ elmnt . removeAttribute ( 'inc' ) ;
1610 }
11+ } catch ( error ) {
12+ console . error ( error ) ;
1713 }
18- } ;
14+ }
15+ }
You can’t perform that action at this time.
0 commit comments