Access-Control-Allow-Origin' header is present on the requested resource.
时间: 2023-10-17 12:33:46 浏览: 52
The error message "Access-Control-Allow-Origin' header is present on the requested resource" usually occurs when a web page or a web API tries to make a cross-origin request but doesn't have the appropriate CORS (Cross-Origin Resource Sharing) headers set up.
CORS is a security mechanism implemented in browsers to restrict cross-origin requests, meaning requests made from one domain to another. Browsers enforce this mechanism by checking for the presence of specific headers in the server's response.
To resolve this issue, the server hosting the requested resource needs to include the "Access-Control-Allow-Origin" header in its response. This header specifies which origins are allowed to access the resource. For example, if you want to allow all origins, you can set the value to "*". You can also specify a specific origin or a list of origins.
Here's an example of how to set the "Access-Control-Allow-Origin" header in different programming languages:
In Node.js with Express:
```javascript
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
next();
});
```
In PHP:
```php
header("Access-Control-Allow-Origin: *");
```
In Python with Flask:
```python
from flask import Flask
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
```
Make sure to include the appropriate code based on your server-side technology. By setting the correct headers, you should be able to resolve the "Access-Control-Allow-Origin" error.