Skip to content

Commit e6baef5

Browse files
committed
change fetch to axios for index.html and search
1 parent 80b0bf7 commit e6baef5

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

assets/js/search.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
let indexDBKeyword;
44
let 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+
}
2425
catch{
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
3462
function convertKeywordsToKeyword(indexDB){

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<!-- css -->
1212
<link rel="stylesheet" href="assets/css/main.css">
1313
<!-- JavaScript -->
14+
<script src="assets/jsClass/js/axios/axios.js"></script>
1415
<script src="assets/js/main.js"></script>
1516
<script src="assets/js/menu.js"></script>
1617
<script src="assets/js/search.js"></script>

0 commit comments

Comments
 (0)