简体   繁体   中英

Index.html Script Tag Values Replaced On Run

I'm having an issue with CORS and web page:

  • Web page value is changed before page loads
    • But isn't happening with any other pages
  • I cannot load the homepage properly with jQuery
    • But all other pages with the same script load fine
  • Doesn't work on Chrome
    • But works locally and on Firefox
  • Changed S3 CORS configuration permissions, but hasn't fixed the problem
    • AWS S3 Bucket > Permissions > CORS configuration
<!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.

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