Consume rest api with ajax get
var settings = {
async: true,
crossDomain: true,
url: "http://10.250.252.1:43001/parameter-api/calculation/outlines/",
method: "GET",
headers: {
"Authorization": "Bearer AB2E2DB9C0894F0CAAE8ABBCBDA5E981",
"cache-control": "no-cache",
"Postman-Token": "e8b2a812-41c1-4b78-8e5b-2bbec1e9013f"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
i generated that code from postman, and everything works create there.
but when i try in javascript i get errors(in the console):
OPTIONS http://10.250.252.1:43001/parameter-api/calculation/outlines/
404 (Not Found) Access to XMLHttpRequest at
'http://10.250.252.1:43001/parameter-api/calculation/outlines/' from
origin 'http://localhost:8080' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check: It
does not have HTTP ok status.
but when i remove my header i get only this error:
GET http://10.250.252.1:43001/parameter-api/calculation/outlines/ 401
(Unauthorized)
i use a cors extension for google chrome btw.
basicly i want to get data from that server, the server uses OAuth2 which i have a token for.
can someoen help me out.
ajax api oauth-2.0 cors
add a comment |
var settings = {
async: true,
crossDomain: true,
url: "http://10.250.252.1:43001/parameter-api/calculation/outlines/",
method: "GET",
headers: {
"Authorization": "Bearer AB2E2DB9C0894F0CAAE8ABBCBDA5E981",
"cache-control": "no-cache",
"Postman-Token": "e8b2a812-41c1-4b78-8e5b-2bbec1e9013f"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
i generated that code from postman, and everything works create there.
but when i try in javascript i get errors(in the console):
OPTIONS http://10.250.252.1:43001/parameter-api/calculation/outlines/
404 (Not Found) Access to XMLHttpRequest at
'http://10.250.252.1:43001/parameter-api/calculation/outlines/' from
origin 'http://localhost:8080' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check: It
does not have HTTP ok status.
but when i remove my header i get only this error:
GET http://10.250.252.1:43001/parameter-api/calculation/outlines/ 401
(Unauthorized)
i use a cors extension for google chrome btw.
basicly i want to get data from that server, the server uses OAuth2 which i have a token for.
can someoen help me out.
ajax api oauth-2.0 cors
Thehttp://10.250.252.1:43001/parameter-api/calculation/outlines/
endpoint needs to be configured to respond to unauthenticated OPTIONS requests with a 200 OK. See the explanation at stackoverflow.com/questions/45405983/…
– sideshowbarker
Nov 27 '18 at 3:28
add a comment |
var settings = {
async: true,
crossDomain: true,
url: "http://10.250.252.1:43001/parameter-api/calculation/outlines/",
method: "GET",
headers: {
"Authorization": "Bearer AB2E2DB9C0894F0CAAE8ABBCBDA5E981",
"cache-control": "no-cache",
"Postman-Token": "e8b2a812-41c1-4b78-8e5b-2bbec1e9013f"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
i generated that code from postman, and everything works create there.
but when i try in javascript i get errors(in the console):
OPTIONS http://10.250.252.1:43001/parameter-api/calculation/outlines/
404 (Not Found) Access to XMLHttpRequest at
'http://10.250.252.1:43001/parameter-api/calculation/outlines/' from
origin 'http://localhost:8080' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check: It
does not have HTTP ok status.
but when i remove my header i get only this error:
GET http://10.250.252.1:43001/parameter-api/calculation/outlines/ 401
(Unauthorized)
i use a cors extension for google chrome btw.
basicly i want to get data from that server, the server uses OAuth2 which i have a token for.
can someoen help me out.
ajax api oauth-2.0 cors
var settings = {
async: true,
crossDomain: true,
url: "http://10.250.252.1:43001/parameter-api/calculation/outlines/",
method: "GET",
headers: {
"Authorization": "Bearer AB2E2DB9C0894F0CAAE8ABBCBDA5E981",
"cache-control": "no-cache",
"Postman-Token": "e8b2a812-41c1-4b78-8e5b-2bbec1e9013f"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
i generated that code from postman, and everything works create there.
but when i try in javascript i get errors(in the console):
OPTIONS http://10.250.252.1:43001/parameter-api/calculation/outlines/
404 (Not Found) Access to XMLHttpRequest at
'http://10.250.252.1:43001/parameter-api/calculation/outlines/' from
origin 'http://localhost:8080' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check: It
does not have HTTP ok status.
but when i remove my header i get only this error:
GET http://10.250.252.1:43001/parameter-api/calculation/outlines/ 401
(Unauthorized)
i use a cors extension for google chrome btw.
basicly i want to get data from that server, the server uses OAuth2 which i have a token for.
can someoen help me out.
ajax api oauth-2.0 cors
ajax api oauth-2.0 cors
asked Nov 26 '18 at 13:02
DES PRODES PRO
15
15
Thehttp://10.250.252.1:43001/parameter-api/calculation/outlines/
endpoint needs to be configured to respond to unauthenticated OPTIONS requests with a 200 OK. See the explanation at stackoverflow.com/questions/45405983/…
– sideshowbarker
Nov 27 '18 at 3:28
add a comment |
Thehttp://10.250.252.1:43001/parameter-api/calculation/outlines/
endpoint needs to be configured to respond to unauthenticated OPTIONS requests with a 200 OK. See the explanation at stackoverflow.com/questions/45405983/…
– sideshowbarker
Nov 27 '18 at 3:28
The
http://10.250.252.1:43001/parameter-api/calculation/outlines/
endpoint needs to be configured to respond to unauthenticated OPTIONS requests with a 200 OK. See the explanation at stackoverflow.com/questions/45405983/…– sideshowbarker
Nov 27 '18 at 3:28
The
http://10.250.252.1:43001/parameter-api/calculation/outlines/
endpoint needs to be configured to respond to unauthenticated OPTIONS requests with a 200 OK. See the explanation at stackoverflow.com/questions/45405983/…– sideshowbarker
Nov 27 '18 at 3:28
add a comment |
1 Answer
1
active
oldest
votes
Add this to your headers settings:
Access-Control-Allow-Origin: *
It's often not a good idea to blindly add a wildcard as origin. I suggest editing the answer to adding only required hostnames.
– Kordonme
Nov 26 '18 at 13:19
it doesn't work, when i do it without extension it gives me another error: Access to XMLHttpRequest at '10.250.252.1:43001/parameter-api/calculation/outlines' from origin 'localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. when i add the "Access-Control-Allow-Origin" : "*" and enable the cors extension, still wouldn't work
– DES PRO
Nov 26 '18 at 13:32
I see, it's a real CORS problem. Check this restlet.com/company/blog/2016/09/27/how-to-fix-cors-problems
– Zineb
Nov 26 '18 at 15:03
I fixed it, had to disable web security and data user on google chrome for it to work, tough i had cors extension, the server api is also gonna get adjusted itself for prevent things like that happens. thanks for you time
– DES PRO
Nov 30 '18 at 13:23
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f53481730%2fconsume-rest-api-with-ajax-get%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Add this to your headers settings:
Access-Control-Allow-Origin: *
It's often not a good idea to blindly add a wildcard as origin. I suggest editing the answer to adding only required hostnames.
– Kordonme
Nov 26 '18 at 13:19
it doesn't work, when i do it without extension it gives me another error: Access to XMLHttpRequest at '10.250.252.1:43001/parameter-api/calculation/outlines' from origin 'localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. when i add the "Access-Control-Allow-Origin" : "*" and enable the cors extension, still wouldn't work
– DES PRO
Nov 26 '18 at 13:32
I see, it's a real CORS problem. Check this restlet.com/company/blog/2016/09/27/how-to-fix-cors-problems
– Zineb
Nov 26 '18 at 15:03
I fixed it, had to disable web security and data user on google chrome for it to work, tough i had cors extension, the server api is also gonna get adjusted itself for prevent things like that happens. thanks for you time
– DES PRO
Nov 30 '18 at 13:23
add a comment |
Add this to your headers settings:
Access-Control-Allow-Origin: *
It's often not a good idea to blindly add a wildcard as origin. I suggest editing the answer to adding only required hostnames.
– Kordonme
Nov 26 '18 at 13:19
it doesn't work, when i do it without extension it gives me another error: Access to XMLHttpRequest at '10.250.252.1:43001/parameter-api/calculation/outlines' from origin 'localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. when i add the "Access-Control-Allow-Origin" : "*" and enable the cors extension, still wouldn't work
– DES PRO
Nov 26 '18 at 13:32
I see, it's a real CORS problem. Check this restlet.com/company/blog/2016/09/27/how-to-fix-cors-problems
– Zineb
Nov 26 '18 at 15:03
I fixed it, had to disable web security and data user on google chrome for it to work, tough i had cors extension, the server api is also gonna get adjusted itself for prevent things like that happens. thanks for you time
– DES PRO
Nov 30 '18 at 13:23
add a comment |
Add this to your headers settings:
Access-Control-Allow-Origin: *
Add this to your headers settings:
Access-Control-Allow-Origin: *
edited Nov 26 '18 at 14:48
Kordonme
1,44011429
1,44011429
answered Nov 26 '18 at 13:14
ZinebZineb
262
262
It's often not a good idea to blindly add a wildcard as origin. I suggest editing the answer to adding only required hostnames.
– Kordonme
Nov 26 '18 at 13:19
it doesn't work, when i do it without extension it gives me another error: Access to XMLHttpRequest at '10.250.252.1:43001/parameter-api/calculation/outlines' from origin 'localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. when i add the "Access-Control-Allow-Origin" : "*" and enable the cors extension, still wouldn't work
– DES PRO
Nov 26 '18 at 13:32
I see, it's a real CORS problem. Check this restlet.com/company/blog/2016/09/27/how-to-fix-cors-problems
– Zineb
Nov 26 '18 at 15:03
I fixed it, had to disable web security and data user on google chrome for it to work, tough i had cors extension, the server api is also gonna get adjusted itself for prevent things like that happens. thanks for you time
– DES PRO
Nov 30 '18 at 13:23
add a comment |
It's often not a good idea to blindly add a wildcard as origin. I suggest editing the answer to adding only required hostnames.
– Kordonme
Nov 26 '18 at 13:19
it doesn't work, when i do it without extension it gives me another error: Access to XMLHttpRequest at '10.250.252.1:43001/parameter-api/calculation/outlines' from origin 'localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. when i add the "Access-Control-Allow-Origin" : "*" and enable the cors extension, still wouldn't work
– DES PRO
Nov 26 '18 at 13:32
I see, it's a real CORS problem. Check this restlet.com/company/blog/2016/09/27/how-to-fix-cors-problems
– Zineb
Nov 26 '18 at 15:03
I fixed it, had to disable web security and data user on google chrome for it to work, tough i had cors extension, the server api is also gonna get adjusted itself for prevent things like that happens. thanks for you time
– DES PRO
Nov 30 '18 at 13:23
It's often not a good idea to blindly add a wildcard as origin. I suggest editing the answer to adding only required hostnames.
– Kordonme
Nov 26 '18 at 13:19
It's often not a good idea to blindly add a wildcard as origin. I suggest editing the answer to adding only required hostnames.
– Kordonme
Nov 26 '18 at 13:19
it doesn't work, when i do it without extension it gives me another error: Access to XMLHttpRequest at '10.250.252.1:43001/parameter-api/calculation/outlines' from origin 'localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. when i add the "Access-Control-Allow-Origin" : "*" and enable the cors extension, still wouldn't work
– DES PRO
Nov 26 '18 at 13:32
it doesn't work, when i do it without extension it gives me another error: Access to XMLHttpRequest at '10.250.252.1:43001/parameter-api/calculation/outlines' from origin 'localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. when i add the "Access-Control-Allow-Origin" : "*" and enable the cors extension, still wouldn't work
– DES PRO
Nov 26 '18 at 13:32
I see, it's a real CORS problem. Check this restlet.com/company/blog/2016/09/27/how-to-fix-cors-problems
– Zineb
Nov 26 '18 at 15:03
I see, it's a real CORS problem. Check this restlet.com/company/blog/2016/09/27/how-to-fix-cors-problems
– Zineb
Nov 26 '18 at 15:03
I fixed it, had to disable web security and data user on google chrome for it to work, tough i had cors extension, the server api is also gonna get adjusted itself for prevent things like that happens. thanks for you time
– DES PRO
Nov 30 '18 at 13:23
I fixed it, had to disable web security and data user on google chrome for it to work, tough i had cors extension, the server api is also gonna get adjusted itself for prevent things like that happens. thanks for you time
– DES PRO
Nov 30 '18 at 13:23
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.
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%2f53481730%2fconsume-rest-api-with-ajax-get%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
The
http://10.250.252.1:43001/parameter-api/calculation/outlines/
endpoint needs to be configured to respond to unauthenticated OPTIONS requests with a 200 OK. See the explanation at stackoverflow.com/questions/45405983/…– sideshowbarker
Nov 27 '18 at 3:28