Alexander Mills
Alexander Mills

Reputation: 100370

Calling javascript script from html

I have a simple javascript file like so:

$(document).ready(function () {
    alert("my controller");
});

I have an HTML file like so:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript" src="/js/generateLineupController.js"></script>
</body>
</html>

for the love of all things holy why in the world would the alert not show? I get a 200 on GET for the javascript file, so it's loading.

Upvotes: 1

Views: 58

Answers (2)

user149341
user149341

Reputation:

Several problems here.

  1. You're trying to load the script twice for some reason. Don't do that. Load it in <head>, or at the end of <body>, but not both.

  2. You're trying to use jQuery syntax ($(...)), but you haven't loaded the jQuery library. You'll need that.

Upvotes: 4

elixenide
elixenide

Reputation: 44851

The $(document).ready(...) indicates that you are trying to use jQuery, but you aren't loading jQuery in your page. Check your console log; you will see the errors there.

Also, there's no need to load the script twice with two <script> tags; just load it once.

Upvotes: 2

Related Questions