JS Fetch takes only OPTIONS request and print that out
up vote
0
down vote
favorite
Im trying to make a request from my React App to my backend server, the frontend do a OPTIONS request and that is OK, the problem is that my then on the fetch console logs the OPTIONS response, and not the real response that is made efter the OPTIONS request.
fetch('http://localhost:8080/api/kp/ticket', {
headers: {
"token": sessionStorage.getItem('token')
},
mode: 'cors',
method: 'GET'
}).then(data => console.log(data));
javascript cors fetch-api
add a comment |
up vote
0
down vote
favorite
Im trying to make a request from my React App to my backend server, the frontend do a OPTIONS request and that is OK, the problem is that my then on the fetch console logs the OPTIONS response, and not the real response that is made efter the OPTIONS request.
fetch('http://localhost:8080/api/kp/ticket', {
headers: {
"token": sessionStorage.getItem('token')
},
mode: 'cors',
method: 'GET'
}).then(data => console.log(data));
javascript cors fetch-api
Even if you say the proposed answer works for you, I still think it is a workaround rather than a fix for the underlying problem. Pre-flight requests are supposed to be handled transparently by the browser, you should not get “in contact” with that in your code at all.
– CBroe
Jul 18 at 13:20
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Im trying to make a request from my React App to my backend server, the frontend do a OPTIONS request and that is OK, the problem is that my then on the fetch console logs the OPTIONS response, and not the real response that is made efter the OPTIONS request.
fetch('http://localhost:8080/api/kp/ticket', {
headers: {
"token": sessionStorage.getItem('token')
},
mode: 'cors',
method: 'GET'
}).then(data => console.log(data));
javascript cors fetch-api
Im trying to make a request from my React App to my backend server, the frontend do a OPTIONS request and that is OK, the problem is that my then on the fetch console logs the OPTIONS response, and not the real response that is made efter the OPTIONS request.
fetch('http://localhost:8080/api/kp/ticket', {
headers: {
"token": sessionStorage.getItem('token')
},
mode: 'cors',
method: 'GET'
}).then(data => console.log(data));
javascript cors fetch-api
javascript cors fetch-api
asked Jul 18 at 13:09
ImJezz
538
538
Even if you say the proposed answer works for you, I still think it is a workaround rather than a fix for the underlying problem. Pre-flight requests are supposed to be handled transparently by the browser, you should not get “in contact” with that in your code at all.
– CBroe
Jul 18 at 13:20
add a comment |
Even if you say the proposed answer works for you, I still think it is a workaround rather than a fix for the underlying problem. Pre-flight requests are supposed to be handled transparently by the browser, you should not get “in contact” with that in your code at all.
– CBroe
Jul 18 at 13:20
Even if you say the proposed answer works for you, I still think it is a workaround rather than a fix for the underlying problem. Pre-flight requests are supposed to be handled transparently by the browser, you should not get “in contact” with that in your code at all.
– CBroe
Jul 18 at 13:20
Even if you say the proposed answer works for you, I still think it is a workaround rather than a fix for the underlying problem. Pre-flight requests are supposed to be handled transparently by the browser, you should not get “in contact” with that in your code at all.
– CBroe
Jul 18 at 13:20
add a comment |
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
try this
fetch('http://localhost:8080/api/kp/ticket', {
headers: {
"token": sessionStorage.getItem('token')
},
mode: 'cors',
method: 'GET'
}).then(data => (data.json())
.then(res => console.log(res));
Thank you very much! This solved the issue :)
– ImJezz
Jul 18 at 13:16
add a comment |
up vote
0
down vote
Check in "Other" tab in chrome devtools. Not in XHR
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
try this
fetch('http://localhost:8080/api/kp/ticket', {
headers: {
"token": sessionStorage.getItem('token')
},
mode: 'cors',
method: 'GET'
}).then(data => (data.json())
.then(res => console.log(res));
Thank you very much! This solved the issue :)
– ImJezz
Jul 18 at 13:16
add a comment |
up vote
4
down vote
accepted
try this
fetch('http://localhost:8080/api/kp/ticket', {
headers: {
"token": sessionStorage.getItem('token')
},
mode: 'cors',
method: 'GET'
}).then(data => (data.json())
.then(res => console.log(res));
Thank you very much! This solved the issue :)
– ImJezz
Jul 18 at 13:16
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
try this
fetch('http://localhost:8080/api/kp/ticket', {
headers: {
"token": sessionStorage.getItem('token')
},
mode: 'cors',
method: 'GET'
}).then(data => (data.json())
.then(res => console.log(res));
try this
fetch('http://localhost:8080/api/kp/ticket', {
headers: {
"token": sessionStorage.getItem('token')
},
mode: 'cors',
method: 'GET'
}).then(data => (data.json())
.then(res => console.log(res));
answered Jul 18 at 13:14
Shorya Vaish
14316
14316
Thank you very much! This solved the issue :)
– ImJezz
Jul 18 at 13:16
add a comment |
Thank you very much! This solved the issue :)
– ImJezz
Jul 18 at 13:16
Thank you very much! This solved the issue :)
– ImJezz
Jul 18 at 13:16
Thank you very much! This solved the issue :)
– ImJezz
Jul 18 at 13:16
add a comment |
up vote
0
down vote
Check in "Other" tab in chrome devtools. Not in XHR
add a comment |
up vote
0
down vote
Check in "Other" tab in chrome devtools. Not in XHR
add a comment |
up vote
0
down vote
up vote
0
down vote
Check in "Other" tab in chrome devtools. Not in XHR
Check in "Other" tab in chrome devtools. Not in XHR
answered Nov 20 at 0:22
HerberthObregon
643712
643712
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51402890%2fjs-fetch-takes-only-options-request-and-print-that-out%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Even if you say the proposed answer works for you, I still think it is a workaround rather than a fix for the underlying problem. Pre-flight requests are supposed to be handled transparently by the browser, you should not get “in contact” with that in your code at all.
– CBroe
Jul 18 at 13:20