22
33let indexDBKeyword ;
44let indexDB ;
5- fetchIndexDB ( ) ;
5+ axiosJsonDB ( ) ;
6+ // fetchIndexDB(); // Old function that works by fetch
67
7- async function fetchIndexDB ( ) {
8+ async function axiosJsonDB ( ) {
89 try {
9- let response = await fetch ( 'http://localhost:3000/indexDB' ) ;
10+ let response = await axios . get ( 'http://localhost:3000/indexDB' ) ;
1011 if ( response . status === 200 ) {
1112 loaderStatus ( true ) ;
12- let indexDataBase = await response . json ( ) ;
13+ let indexDataBase = response . data ;
1314 // make a new object without keywords
1415 indexDB = convertKeywordsToKeyword ( indexDataBase ) ;
1516 const indexDBKey = indexDB . map ( value => value . keyword ) ;
@@ -20,15 +21,42 @@ async function fetchIndexDB(){
2021 } else {
2122 loaderStatus ( false , `${ response . statusText } (${ response . status } )` ) ;
2223 }
23- }
24+ }
2425catch {
2526 const errorMessage = "Can't Find the 'http://localhost:3000/indexDB'<br>" +
2627 "Please goto 'node_modules\\.bin'<br>" +
2728 "and" +
2829 "<br>run 'json-server --watch ..\\..\\assets\\DB\\jsonDB.json' " ;
2930 loaderStatus ( false , errorMessage ) ;
31+ }
3032}
31- }
33+
34+ // Old function that works by fetch
35+ // async function fetchIndexDB(){
36+ // try{
37+ // let response = await fetch('http://localhost:3000/indexDB');
38+ // if (response.status === 200) {
39+ // loaderStatus(true);
40+ // let indexDataBase = await response.json();
41+ // // make a new object without keywords
42+ // indexDB = convertKeywordsToKeyword(indexDataBase);
43+ // const indexDBKey = indexDB.map(value => value.keyword);
44+ // /// new set to remove duplicate and again convert to array by ...
45+ // indexDBKeyword = [...new Set(indexDBKey)];
46+ // document.getElementById("searchbar").addEventListener("keyup",function(e){search(indexDB)});
47+ // autocomplete(document.getElementById("searchbar"), indexDBKeyword);
48+ // } else {
49+ // loaderStatus(false,`${response.statusText} (${response.status})`);
50+ // }
51+ // }
52+ // catch{
53+ // const errorMessage = "Can't Find the 'http://localhost:3000/indexDB'<br>"+
54+ // "Please goto 'node_modules\\.bin'<br>"+
55+ // "and"+
56+ // "<br>run 'json-server --watch ..\\..\\assets\\DB\\jsonDB.json' ";
57+ // loaderStatus(false,errorMessage);
58+ // }
59+ // }
3260
3361// ability to use multi words as keywords at indexDB
3462function convertKeywordsToKeyword ( indexDB ) {
0 commit comments