CORS error with jquery

后端 未结 4 1130
后悔当初
后悔当初 2020-12-01 21:58

I\'m currently working on a project using the cloudapp API and I\'m using jquery. Here is my code:

 $.ajax({
            headers: { \"Accept\": \"application         


        
4条回答
  •  一生所求
    2020-12-01 22:56

    An important note for those newer coders is that everything on http://enable-cors.org/server.html assumes you have a server running. If you're new, like I was originally, these type of answers don't help.

    If you've just made some code on your computer, CodePen, etc - you can't configure this.

    There's an important difference between server-side and client-side scripting - your jquery is running on the client side (that is, the users computer / browser) and as such there's no such thing as setting the headers there.

    I finally started making progress with this issue when I set up my own server and my own PHP files (PHP is server-side, as such its processed on the server - not the browser) and was able to start making requests just fine.

    Adding this for anyone who is being drowned in answers involving the "Header set Access-Control-Allow-Origin "*" answer. It really frustrated me when I started as well.

提交回复
热议问题