I'm having an issue with CORS and web page:
<!DOCTYPE html>
<html lang="en">
<head>
<script
type="text/javascript" crossorigin="anonymous">$(function () { $.get("assets/head.html", function (data) { $("head").prepend(data); }); });</script>
</head>
<body class="container">
</body>
</html>
Turns to:
<!DOCTYPE html>
<html lang="en">
<head>
<script
type="text/javascript" crossorigin="anonymous">$(function () { $.get("https://s3-example.amazonaws.com/aws-codestar-example/public/assets/head.html", function (data) { $("head").prepend(data); }); });</script>
</head>
<body class="container">
</body>
</html>
The error is:
Access to XMLHttpRequest at 'https://s3-example.amazonaws.com/aws-codestar-example/public/assets/head.html' from origin 'http://example2.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Why is the source changing before read by Chrome?
Write the script in another page & link it in the bottom head or body tag. As like:
<script src="Right the link page" type="text/javascript">
function...
</script>
</body>
Or:
<script type="text/javascript" src="Right the link page">
function...
</script>
</head>
Write the script language in the head tag and try or in the bottom body tag. As like:
<script type="text/javascript">function...
</script>`
</body>
Or
<script type="text/javascript"></script>`
</head>
Than isn't than please remove your browser history, & close all tab than right the URL in the browser tab & run.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.