Resolve CORS issue without changing services.yml file

The name of the pictureThe name of the pictureThe name of the pictureClash 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.










share|improve this question





























    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.










    share|improve this question

























      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.










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 31 mins ago









      leymannx

      5,94842356




      5,94842356










      asked 44 mins ago









      Ankit Shah

      1207




      1207




















          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.






          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "220"
            ;
            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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            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






























            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.






            share|improve this answer
























              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.






              share|improve this answer






















                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.






                share|improve this answer













                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 37 mins ago









                Clive♦

                145k13245287




                145k13245287



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    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













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery