Resolve CORS issue without changing services.yml file
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I have below in routing.yml
sample.post:
path: '/sample/post'
defaults:
_controller: 'DrupalsampleControllerSampleController::postData'
methods: [POST]
requirements:
_access: 'TRUE'
_format: 'json'
In services.yml no change it will be same as default. I don't want to change in service.yml by enabling cors config.
When I call using jQuery.
jQuery.ajax(
url: 'http://localhost/sample/post',
contentType: "application/json",
type: 'POST',
complete: function (data)
console.log(data);
);
It gives
Failed to load http://localhost/sample/post: Response to preflight
request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost' is therefore not allowed access.
Can I achieve w/o enabling cors config? If I enable cors then it works fine.
8
add a comment |Â
up vote
1
down vote
favorite
I have below in routing.yml
sample.post:
path: '/sample/post'
defaults:
_controller: 'DrupalsampleControllerSampleController::postData'
methods: [POST]
requirements:
_access: 'TRUE'
_format: 'json'
In services.yml no change it will be same as default. I don't want to change in service.yml by enabling cors config.
When I call using jQuery.
jQuery.ajax(
url: 'http://localhost/sample/post',
contentType: "application/json",
type: 'POST',
complete: function (data)
console.log(data);
);
It gives
Failed to load http://localhost/sample/post: Response to preflight
request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost' is therefore not allowed access.
Can I achieve w/o enabling cors config? If I enable cors then it works fine.
8
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have below in routing.yml
sample.post:
path: '/sample/post'
defaults:
_controller: 'DrupalsampleControllerSampleController::postData'
methods: [POST]
requirements:
_access: 'TRUE'
_format: 'json'
In services.yml no change it will be same as default. I don't want to change in service.yml by enabling cors config.
When I call using jQuery.
jQuery.ajax(
url: 'http://localhost/sample/post',
contentType: "application/json",
type: 'POST',
complete: function (data)
console.log(data);
);
It gives
Failed to load http://localhost/sample/post: Response to preflight
request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost' is therefore not allowed access.
Can I achieve w/o enabling cors config? If I enable cors then it works fine.
8
I have below in routing.yml
sample.post:
path: '/sample/post'
defaults:
_controller: 'DrupalsampleControllerSampleController::postData'
methods: [POST]
requirements:
_access: 'TRUE'
_format: 'json'
In services.yml no change it will be same as default. I don't want to change in service.yml by enabling cors config.
When I call using jQuery.
jQuery.ajax(
url: 'http://localhost/sample/post',
contentType: "application/json",
type: 'POST',
complete: function (data)
console.log(data);
);
It gives
Failed to load http://localhost/sample/post: Response to preflight
request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost' is therefore not allowed access.
Can I achieve w/o enabling cors config? If I enable cors then it works fine.
8
8
edited 31 mins ago
leymannx
5,94842356
5,94842356
asked 44 mins ago
Ankit Shah
1207
1207
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
Can I achieve w/o enabling cors config?
No. Without CORS configured, the server and browser will correctly conspire to reject the request.
You could implement it yourself, rather than using services.yml, but something needs to set the headers. And at the point where all you need to do is make a few simple edits to a configuration file, I'd question why you would want to write all that extra code yourself.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Can I achieve w/o enabling cors config?
No. Without CORS configured, the server and browser will correctly conspire to reject the request.
You could implement it yourself, rather than using services.yml, but something needs to set the headers. And at the point where all you need to do is make a few simple edits to a configuration file, I'd question why you would want to write all that extra code yourself.
add a comment |Â
up vote
2
down vote
Can I achieve w/o enabling cors config?
No. Without CORS configured, the server and browser will correctly conspire to reject the request.
You could implement it yourself, rather than using services.yml, but something needs to set the headers. And at the point where all you need to do is make a few simple edits to a configuration file, I'd question why you would want to write all that extra code yourself.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Can I achieve w/o enabling cors config?
No. Without CORS configured, the server and browser will correctly conspire to reject the request.
You could implement it yourself, rather than using services.yml, but something needs to set the headers. And at the point where all you need to do is make a few simple edits to a configuration file, I'd question why you would want to write all that extra code yourself.
Can I achieve w/o enabling cors config?
No. Without CORS configured, the server and browser will correctly conspire to reject the request.
You could implement it yourself, rather than using services.yml, but something needs to set the headers. And at the point where all you need to do is make a few simple edits to a configuration file, I'd question why you would want to write all that extra code yourself.
answered 37 mins ago
Clive♦
145k13245287
145k13245287
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f271384%2fresolve-cors-issue-without-changing-services-yml-file%23new-answer', 'question_page');
);
Post as a guest
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
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
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