Skip to content

Commit 3ea1d84

Browse files
committed
add CORS in fetch
1 parent 7bf4ec4 commit 3ea1d84

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta charset="UTF-8">
66
<meta http-equiv="X-UA-Compatible" content="IE=edge">
77
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<link rel="shortcut icon" href="https://cdn-icons-png.flaticon.com/512/4329/4329416.png" type="image/x-icon">
89
<!-- <link rel="stylesheet" href="./styles/style.css"> -->
910
<!-- <link rel="stylesheet" href="./styles/bootstrap.min.css"> -->
1011

script.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ form.addEventListener('submit', event => {
4040
const sloka = document.querySelector('#sloka').value;
4141
const url = `https://bhagavadgitaapi.in/slok/${chapter}/${sloka}`;
4242

43-
44-
//tried code
43+
4544
// Check if data is already in local storage
4645
const storedData = localStorage.getItem(`gita${chapter}-${sloka}`);
4746
if (storedData) {
@@ -58,7 +57,15 @@ form.addEventListener('submit', event => {
5857
`;
5958
} else {
6059
// Data is not in local storage, make API request
61-
fetch(url)
60+
var headers = {};
61+
fetch(url,
62+
{
63+
method : "GET",
64+
mode: 'cors',
65+
headers: {
66+
'Access-Control-Allow-Origin':'*'
67+
}
68+
})
6269
.then(response => response.json())
6370
.then(data => {
6471
// Store data in local storage

0 commit comments

Comments
 (0)