简体   繁体   English

在开发过程中如何在javascript中使用假对象并避免CORS错误

[英]How to use fake object in javascript during development and avoid CORS error

In a web page I load from a REST API some data to display in the page. 在网页中,我从REST API加载一些数据以显示在页面中。 But during developing with Visual Studio Code and Live Server I have CORS errors because I'm trying to get data from the production source. 但是在使用Visual Studio Code和Live Server进行开发的过程中,我遇到了CORS错误,因为我试图从生产源中获取数据。 How can I develop and avoid this error? 如何开发并避免此错误? Thanks! 谢谢!

If this is just a problem during development - Depending on your browser there are extensions available to disable CORS. 如果这只是开发过程中的问题-取决于您的浏览器,可以使用一些扩展来禁用CORS。

If you are using chrome there is one called Allow-Control-Allow-Origin: * . 如果您使用的是chrome,则有一种称为Allow-Control-Allow-Origin:*

There is a similar one for firefox, Allow CORS: Access-Control-Allow-Origin . Firefox有一个类似的类, 允许CORS:Access-Control-Allow-Origin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM