How to include js file in html project?

Asked

Viewed 198 times

0

In my project, I’m trying to include a . js file, but it’s showing the error Uncaught SyntaxError: Unexpected token < every time I include the file as follows <script type="text/javascript" src="dashboard/dist/js/main.js"></script>. It turns out that this problem only exists when I’m calling my main library that way.

<?php require "lib/Url.class.php"; ?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset='utf-8'/>
        <meta http-equiv='X-UA-Compatible' content='IE=edge'/>
        <title>Dashboard - Marketing</title>
        <meta name='viewport' content='width=device-width, initial-scale=1'/>
        <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css'/>
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha256-3edrmyuQ0w65f8gfBsqowzjJe2iM6n0nKciPUp8y+7E="  crossorigin="anonymous"></script>
        <script src='https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js'></script>
        <script type="text/javascript" src="dashboard/dist/js/main.js"></script>
        <link href='https://fonts.googleapis.com/icon?family=Material+Icons' rel='stylesheet'/>
        
    </head>
    <nav class="nav-extended #0d47a1 blue darken-4">
        <div class="nav-wrapper container">
            <a href="#" class="brand-logo">Logo</a>
            <a href="#" data-target="mobile-demo" class="sidenav-trigger"><i class="material-icons">menu</i></a>
            <ul id="nav-mobile" class="right hide-on-med-and-down">
                <li><a class="nav-link text-white" href="<?php echo URL::getBase(); ?>main">Home</a></li>
                <li><a class="nav-link text-white" href="<?php echo URL::getBase(); ?>dados">Dados</a></li>
                <li><a class="nav-link text-white" href="<?php echo URL::getBase(); ?>precos">Preços</a></li>
            </ul>
        </div>
    </nav>

    <ul class="sidenav" id="mobile-demo">
        <li><a class="" href="<?php echo URL::getBase(); ?>main">Home</a></li>
        <li><a class="" href="<?php echo URL::getBase(); ?>dados">Dados</a></li>
        <li><a class="" href="<?php echo URL::getBase(); ?>precos">Preços</a></li>
    </ul>

  • Face the problem there it seems is the file main.js, it is causing the problem and not his call. Just vc open the browser console and see the error message. It shows the file and file line that are having problems.

  • @Leandrade I did this and my main.js file is empty. The error that the console shows is described above. It’s like you’ve got a wrong '<' inserted.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.