Estoy tratando de mostrar el sitio web de wikipedia en mi sitio, pero tengo un problema con cors. Por favor, ¿alguien puede ayudarme? Probé tantas cosas pero nada me funcionó.
error:
Access to fetch at 'https://en.wikipedia.org/w/index.php?title=elon_musk&action=render' 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.código:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div id="content"></div> </body> <script> contentUrl = 'https://en.wikipedia.org/w/index.php?title=' afterContentUrl = '&action=render' title="elon_musk" let url = contentUrl + title + afterContentUrl fetch(url) .then(function (response) { return response.text(); }) .then((data) => { console.log(data) document.getElementById('content').innerHTML = data }) </script> </html>https://www.mediawiki.org/wiki/API:Main_page
Gracias:)