mercredi 16 août 2017

JavaScript does not execute when hosted on server

I have an ASP.NET MVC web app that I'm making. There are some webpages where I would like to use client side javascript. When I run a webpage with JS on it on localhost, everything is fine. The JS execute as expected.

When it's hosted on a server, however, nothing inside the script tags execute. This includes imported libraries. Here is the html of a sample page (extracted from a browser, actual file is .cshtml):

<!DOCTYPE html>
<html >
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>sample</title>

    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css">

</head>
<body>

    <!--Accessibility requirement-->
    <a class="m-skip-to-main" href="#mainContent" tabindex="0">Skip to main content</a>



    <a href="#" class="m-back-to-top" aria-disabled="true">
        <div class="c-glyph glyph-up" aria-label="Back to top"></div>
    </a>

    <!--Body Content-->
    <main id="mainContent" data-grid="container" role="Main">

        <p id="testing"></p>

        <pre class="highlight"><code>
            Hello hello hello     
        </code></pre>

    </main>



    <!--JavaScript-->
    <script src="http://ift.tt/2vIS2kr"></script>
    <script src="http://ift.tt/2wU6uW5"></script>
    <script src="http://ift.tt/2rYxCS9"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>

    <script type="text/javascript">
        $("#testing").append("This is a message from javascript");
        console.log("This is a message");
    </script>


</body>
</html>

I don't really have a lot of experience with ASP.NET and I'm a junior developer, so any help or suggestions would be welcome. I know ASP.NET is mainly supposed to be server side scripting, but I was under the impression that you could also use JS for some things if needed. I'm hosting on Azure if that makes any difference.

Thanks




Aucun commentaire:

Enregistrer un commentaire