Uncaught (in promise) TypeError: Failed to fetch and Cors error

前端 未结 4 1048
无人共我
无人共我 2020-11-30 04:05

having a problem with getting data back from database. I am trying my best to explain the problem.

1.If I leave \"mode\":\"no-cors\" inside the code below, then I ca

4条回答
  •  执笔经年
    2020-11-30 04:22

    See mozilla.org's write-up on how CORS works.

    You'll need your server to send back the proper response headers, something like:

    Access-Control-Allow-Origin: http://foo.example
    Access-Control-Allow-Methods: POST, PUT, GET, OPTIONS
    Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization
    

    Bear in mind you can use "*" for Access-Control-Allow-Origin that will only work if you're trying to pass Authentication data. In that case, you need to explicitly list the origin domains you want to allow. To allow multiple domains, see this post

提交回复
热议问题