How to solve 'Redirect has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header'?

前端 未结 17 2116
遥遥无期
遥遥无期 2020-11-27 13:12

I am working on an app using Vue js. According to my setting I need to pass to a variable to my URL when setting change.



        
相关标签:
17条回答
  • 2020-11-27 13:40
    $.get('https://172.16.1.157:8002/firstcolumn/' + c1v + '/' + c1b, function (data) { 
      // some code...
    });
    

    Just put "https" .

    0 讨论(0)
  • 2020-11-27 13:41

    When you have this problem with Chrome, you don't need an Extension.
    Start Chrome from the Console:

    chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security

    Maybe you have to close all Tabs in Chrome and restart it.

    0 讨论(0)
  • 2020-11-27 13:41

    you have to customize security for your browser or allow permission through customizing security. (it is impractical for your local testing) to know more about please go through the link.
    https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

    0 讨论(0)
  • 2020-11-27 13:43

    Ask the person maintaining the server at http://172.16.1.157:8002/ to add your hostname to Access-Control-Allow-Origin hosts, the server should return a header similar to the following with the response-

    Access-Control-Allow-Origin: yourhostname:port
    
    0 讨论(0)
  • 2020-11-27 13:45

    You can solve this temporarily by using the Firefox add-on, CORS Everywhere. Just open Firefox, press Ctrl+Shift+A , search the add-on and add it!

    0 讨论(0)
  • 2020-11-27 13:45

    You won't believe this, Make sure to add "." at the end of the "url"

    I got a similar error with this code:

    fetch(https://itunes.apple.com/search?term=jack+johnson)
    .then( response => {
        return response.json();
    })
    .then(data => {
        console.log(data.results);
    }).catch(error => console.log('Request failed:', error))
    

    The error I got:

     Access to fetch at 'https://itunes.apple.com/search?term=jack+johnson'
     from origin 'http://127.0.0.1:5500' has been blocked by CORS policy:
     No 'Access-Control-Allow-Origin' header is present on the requested
     resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
    

    But I realized after a lot of research that the problem was that I did not copy the right URL address from the iTunes API documentation.

    It should have been

    https://itunes.apple.com/search?term=jack+johnson.

    not

    https://itunes.apple.com/search?term=jack+johnson

    Notice the dot at the end

    There is a huge explanation about why the dot is important quoting issues about DNS and character encoding but the truth is you probably do not care. Try adding the dot it might work for you too.

    When I added the "." everything worked like a charm.

    I hope it works for you too.

    0 讨论(0)
提交回复
热议问题